From 10199ed983988db4326385b591aede7948aa6158 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Sat, 8 Jul 2023 12:03:12 +0800 Subject: [PATCH] fix-gitbook --- pages/[...slug].js | 1 - themes/gitbook/components/NavPostList.js | 7 ++-- themes/gitbook/components/PageNavDrawer.js | 6 ++-- themes/gitbook/index.js | 39 ++++++++++++---------- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/pages/[...slug].js b/pages/[...slug].js index d6900b73..1523c674 100644 --- a/pages/[...slug].js +++ b/pages/[...slug].js @@ -28,7 +28,6 @@ const Slug = props => { */ const validPassword = passInput => { const encrypt = md5(post.slug + passInput) - console.log('passInput', passInput, post.slug) if (passInput && encrypt === post.password) { setLock(false) return true diff --git a/themes/gitbook/components/NavPostList.js b/themes/gitbook/components/NavPostList.js index bf5462a1..0cb8c3bf 100644 --- a/themes/gitbook/components/NavPostList.js +++ b/themes/gitbook/components/NavPostList.js @@ -1,6 +1,7 @@ import NavPostListEmpty from './NavPostListEmpty' import { useRouter } from 'next/router' import NavPostItem from './NavPostItem' +import { useGitBookGlobal } from '..' /** * 博客列表滚动分页 @@ -10,8 +11,8 @@ import NavPostItem from './NavPostItem' * @constructor */ const NavPostList = (props) => { - const { posts = [], currentSearch } = props - const filteredPosts = Object.assign(posts) + const { filteredPosts } = useGitBookGlobal() + const router = useRouter() let selectedSth = false @@ -34,7 +35,7 @@ const NavPostList = (props) => { } if (!filteredPosts || filteredPosts.length === 0) { - return + return } else { return
{/* 文章列表 */} diff --git a/themes/gitbook/components/PageNavDrawer.js b/themes/gitbook/components/PageNavDrawer.js index faa441ed..5f872184 100644 --- a/themes/gitbook/components/PageNavDrawer.js +++ b/themes/gitbook/components/PageNavDrawer.js @@ -8,8 +8,8 @@ import NavPostList from './NavPostList' * @returns {JSX.Element} * @constructor */ -const PageNavDrawer = ({ post, cRef }) => { - const { pageNavVisible, changePageNavVisible, filterPosts } = useGitBookGlobal() +const PageNavDrawer = (props) => { + const { pageNavVisible, changePageNavVisible } = useGitBookGlobal() const switchVisible = () => { changePageNavVisible(!pageNavVisible) } @@ -22,7 +22,7 @@ const PageNavDrawer = ({ post, cRef }) => { ' overflow-y-hidden shadow-card w-72 duration-200 fixed left-1 top-16 rounded py-2 bg-white dark:bg-gray-600'}>
{/* 所有文章列表 */} - +
diff --git a/themes/gitbook/index.js b/themes/gitbook/index.js index bb75e59b..b38afbc2 100644 --- a/themes/gitbook/index.js +++ b/themes/gitbook/index.js @@ -47,16 +47,16 @@ const LayoutBase = (props) => { const router = useRouter() const [tocVisible, changeTocVisible] = useState(false) const [pageNavVisible, changePageNavVisible] = useState(false) - const [filterPosts, setFilterPosts] = useState(allNavPages) + const [filteredPosts, setFilteredPosts] = useState(allNavPages) const showTocButton = post?.toc?.length > 1 useEffect(() => { - setFilterPosts(allNavPages) + setFilteredPosts(allNavPages) }, [post]) return ( - +
@@ -71,11 +71,12 @@ const LayoutBase = (props) => { {slotLeft} {/* 所有文章列表 */} - +
-
+ +
@@ -159,20 +160,22 @@ const LayoutBase = (props) => { */ const LayoutIndex = (props) => { const router = useRouter() - router.push(CONFIG.INDEX_PAGE).then(() => { - // console.log('跳转到指定首页', CONFIG.INDEX_PAGE) - setTimeout(() => { - if (isBrowser()) { - const article = document.getElementById('notion-article') - if (!article) { - console.log('请检查您的Notion数据库中是否包含此slug页面: ', CONFIG.INDEX_PAGE) - const containerInner = document.getElementById('container-inner') - const newHTML = `

配置有误

请在您的notion中添加一个slug为${CONFIG.INDEX_PAGE}的文章
` - containerInner?.insertAdjacentHTML('afterbegin', newHTML) + useEffect(() => { + router.push(CONFIG.INDEX_PAGE).then(() => { + // console.log('跳转到指定首页', CONFIG.INDEX_PAGE) + setTimeout(() => { + if (isBrowser()) { + const article = document.getElementById('notion-article') + if (!article) { + console.log('请检查您的Notion数据库中是否包含此slug页面: ', CONFIG.INDEX_PAGE) + const containerInner = document.getElementById('container-inner') + const newHTML = `

配置有误

请在您的notion中添加一个slug为${CONFIG.INDEX_PAGE}的文章
` + containerInner?.insertAdjacentHTML('afterbegin', newHTML) + } } - } - }, 7 * 1000) - }) + }, 7 * 1000) + }) + }, []) return }