From 3366dd4a6c60ea45515d5dab29ad1c8a9ab730e1 Mon Sep 17 00:00:00 2001 From: LooseLi <1329307562@qq.com> Date: Mon, 26 May 2025 18:11:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20eslint=20=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/gitbook/components/ArticleAround.js | 4 +- themes/gitbook/index.js | 109 ++++++++++---------- themes/nobelium/components/ArticleFooter.js | 38 +++---- themes/plog/components/ArticleFooter.js | 38 +++---- themes/proxio/components/MenuList.js | 8 +- themes/starter/components/MenuList.js | 8 +- themes/theme.js | 6 +- 7 files changed, 108 insertions(+), 103 deletions(-) diff --git a/themes/gitbook/components/ArticleAround.js b/themes/gitbook/components/ArticleAround.js index 56db04ea..4125e1cc 100644 --- a/themes/gitbook/components/ArticleAround.js +++ b/themes/gitbook/components/ArticleAround.js @@ -7,10 +7,12 @@ import Link from 'next/link' * @returns */ export default function ArticleAround({ prev, next }) { + const { locale } = useGlobal() + if (!prev || !next) { return <> } - const { locale } = useGlobal() + return (
{ setHasRedirected(true) // 更新状态,防止多次执行 // 重定向到指定文章 - router.push(index).then(() => { - setTimeout(() => { - const article = document.querySelector( - '#article-wrapper #notion-article' - ) - if (!article) { - console.log( - '请检查您的Notion数据库中是否包含此slug页面: ', - index - ) + await router.push(index) - // 显示错误信息 - const containerInner = document.querySelector( - '#theme-gitbook #container-inner' - ) - const newHTML = `

配置有误

请在您的notion中添加一个slug为${index}的文章
` - containerInner?.insertAdjacentHTML('afterbegin', newHTML) - } - }, 2000) - }) + // 使用setTimeout检查页面加载情况 + setTimeout(() => { + const article = document.querySelector( + '#article-wrapper #notion-article' + ) + if (!article) { + console.log('请检查您的Notion数据库中是否包含此slug页面: ', index) + + // 显示错误信息 + const containerInner = document.querySelector( + '#theme-gitbook #container-inner' + ) + const newHTML = `

配置有误

请在您的notion中添加一个slug为${index}的文章
` + containerInner?.insertAdjacentHTML('afterbegin', newHTML) + } + }, 2000) } } @@ -320,21 +318,18 @@ const LayoutSlug = props => { useEffect(() => { // 404 if (!post) { - setTimeout( - () => { - if (isBrowser) { - const article = document.querySelector( - '#article-wrapper #notion-article' - ) - if (!article) { - router.push('/404').then(() => { - console.warn('找不到页面', router.asPath) - }) - } + setTimeout(() => { + if (isBrowser) { + const article = document.querySelector( + '#article-wrapper #notion-article' + ) + if (!article) { + router.push('/404').then(() => { + console.warn('找不到页面', router.asPath) + }) } - }, - waiting404 - ) + } + }, waiting404) } }, [post]) return ( @@ -451,16 +446,21 @@ const Layout404 = props => { }, 3000) }, []) - return <> -
-
-

404

-
-

{locale.NAV.PAGE_NOT_FOUND_REDIRECT}

-
-
+ return ( + <> +
+
+

+ + 404 +

+
+

{locale.NAV.PAGE_NOT_FOUND_REDIRECT}

+
+
+ ) } /** @@ -609,18 +609,17 @@ const LayoutDashboard = props => { } export { - Layout404, - LayoutArchive, - LayoutBase, - LayoutCategoryIndex, - LayoutDashboard, - LayoutIndex, - LayoutPostList, - LayoutSearch, - LayoutSignIn, - LayoutSignUp, - LayoutSlug, - LayoutTagIndex, - CONFIG as THEME_CONFIG + Layout404, + LayoutArchive, + LayoutBase, + LayoutCategoryIndex, + LayoutDashboard, + LayoutIndex, + LayoutPostList, + LayoutSearch, + LayoutSignIn, + LayoutSignUp, + LayoutSlug, + LayoutTagIndex, + CONFIG as THEME_CONFIG } - diff --git a/themes/nobelium/components/ArticleFooter.js b/themes/nobelium/components/ArticleFooter.js index 628dd05d..db4b5abf 100644 --- a/themes/nobelium/components/ArticleFooter.js +++ b/themes/nobelium/components/ArticleFooter.js @@ -12,22 +12,24 @@ export const ArticleFooter = props => { const router = useRouter() const { locale } = useGlobal() - return
- - - - - - -
+ return ( +
+ + + + + + +
+ ) } diff --git a/themes/plog/components/ArticleFooter.js b/themes/plog/components/ArticleFooter.js index ec65adba..56fc036b 100644 --- a/themes/plog/components/ArticleFooter.js +++ b/themes/plog/components/ArticleFooter.js @@ -13,22 +13,24 @@ export const ArticleFooter = props => { const router = useRouter() const { locale } = useGlobal() - return
- - - - - - -
+ return ( +
+ + + + + + +
+ ) } diff --git a/themes/proxio/components/MenuList.js b/themes/proxio/components/MenuList.js index 0352e8b2..ac5f7a0d 100644 --- a/themes/proxio/components/MenuList.js +++ b/themes/proxio/components/MenuList.js @@ -51,10 +51,6 @@ export const MenuList = props => { links = customMenu } - if (!links || links.length === 0) { - return null - } - const toggleMenu = () => { setShowMenu(!showMenu) // 切换菜单状态 } @@ -63,6 +59,10 @@ export const MenuList = props => { setShowMenu(false) }, [router]) + if (!links || links.length === 0) { + return null + } + return (
{/* 移动端菜单切换按钮 */} diff --git a/themes/starter/components/MenuList.js b/themes/starter/components/MenuList.js index 0352e8b2..ac5f7a0d 100644 --- a/themes/starter/components/MenuList.js +++ b/themes/starter/components/MenuList.js @@ -51,10 +51,6 @@ export const MenuList = props => { links = customMenu } - if (!links || links.length === 0) { - return null - } - const toggleMenu = () => { setShowMenu(!showMenu) // 切换菜单状态 } @@ -63,6 +59,10 @@ export const MenuList = props => { setShowMenu(false) }, [router]) + if (!links || links.length === 0) { + return null + } + return (
{/* 移动端菜单切换按钮 */} diff --git a/themes/theme.js b/themes/theme.js index 3d89f878..451c77bf 100644 --- a/themes/theme.js +++ b/themes/theme.js @@ -79,17 +79,17 @@ export const getBaseLayoutByTheme = theme => { */ export const DynamicLayout = props => { const { theme, layoutName } = props - const SelectedLayout = getLayoutByTheme({ layoutName, theme }) + const SelectedLayout = useLayoutByTheme({ layoutName, theme }) return } /** * 加载主题文件 - * @param {*} router + * @param {*} layoutName * @param {*} theme * @returns */ -export const getLayoutByTheme = ({ layoutName, theme }) => { +export const useLayoutByTheme = ({ layoutName, theme }) => { // const layoutName = getLayoutNameByPath(router.pathname, router.asPath) const LayoutComponents = ThemeComponents[layoutName] || ThemeComponents.LayoutSlug