From 75f2cc050f5dc095d50b6d60769e059d34e17ef9 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Thu, 27 Jul 2023 18:20:06 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E9=9A=8F=E4=BE=BF=E9=80=9B=E9=80=9B?= =?UTF-8?q?=E4=B8=A4=E6=AC=A1=E7=82=B9=E5=87=BB=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/CustomContextMenu.js | 6 +++++- themes/heo/components/Hero.js | 6 ++++-- themes/heo/components/RandomPostButton.js | 11 +++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/components/CustomContextMenu.js b/components/CustomContextMenu.js index 054c04fa..e85f321a 100644 --- a/components/CustomContextMenu.js +++ b/components/CustomContextMenu.js @@ -3,6 +3,7 @@ import { useRouter } from 'next/router' import { useEffect, useState, useRef } from 'react' import { useGlobal } from '@/lib/global' import { saveDarkModeToCookies, THEMES } from '@/themes/theme' +import BLOG from '@/blog.config' /** * 自定义右键菜单 @@ -17,10 +18,13 @@ export default function CustomContextMenu(props) { const { latestPosts } = props const router = useRouter() + /** + * 随机跳转文章 + */ function handleJumpToRandomPost() { const randomIndex = Math.floor(Math.random() * latestPosts.length) const randomPost = latestPosts[randomIndex] - router.push(randomPost.slug) + router.push(`${BLOG.SUB_PATH}/${randomPost?.slug}`) } useEffect(() => { diff --git a/themes/heo/components/Hero.js b/themes/heo/components/Hero.js index cf4dcc66..ff815b9b 100644 --- a/themes/heo/components/Hero.js +++ b/themes/heo/components/Hero.js @@ -55,11 +55,13 @@ function BannerGroup(props) { function Banner(props) { const router = useRouter() const { latestPosts } = props - // 跳转到任意文章 + /** + * 随机跳转文章 + */ function handleClickBanner() { const randomIndex = Math.floor(Math.random() * latestPosts.length) const randomPost = latestPosts[randomIndex] - router.push(randomPost.slug) + router.push(`${BLOG.SUB_PATH}/${randomPost?.slug}`) } return
diff --git a/themes/heo/components/RandomPostButton.js b/themes/heo/components/RandomPostButton.js index 66d6cc85..a8a0597f 100644 --- a/themes/heo/components/RandomPostButton.js +++ b/themes/heo/components/RandomPostButton.js @@ -1,3 +1,5 @@ +import BLOG from '@/blog.config' +import { useGlobal } from '@/lib/global' import { useRouter } from 'next/router' /** @@ -6,13 +8,18 @@ import { useRouter } from 'next/router' export default function RandomPostButton(props) { const { latestPosts } = props const router = useRouter() + const { locale } = useGlobal() + /** + * 随机跳转文章 + */ function handleClick() { const randomIndex = Math.floor(Math.random() * latestPosts.length) const randomPost = latestPosts[randomIndex] - router.push(randomPost.slug) + router.push(`${BLOG.SUB_PATH}/${randomPost?.slug}`) } + return ( -
+
)