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 ( -
+
)