diff --git a/themes/gitbook/components/NavPostList.js b/themes/gitbook/components/NavPostList.js index 7e793871..e43d0498 100644 --- a/themes/gitbook/components/NavPostList.js +++ b/themes/gitbook/components/NavPostList.js @@ -10,13 +10,12 @@ import NavPostItem from './NavPostItem' * @constructor */ const NavPostList = (props) => { - const { filteredPosts } = props - + const { filteredPostGroups } = props const router = useRouter() let selectedSth = false // 处理是否选中 - filteredPosts?.map((group) => { + filteredPostGroups.map((group) => { let groupSelected = false for (const post of group?.items) { if (router.asPath.split('?')[0] === '/' + post.slug) { @@ -29,16 +28,16 @@ const NavPostList = (props) => { }) // 如果都没有选中默认打开第一个 - if (!selectedSth && filteredPosts && filteredPosts.length > 0) { - filteredPosts[0].selected = true + if (!selectedSth && filteredPostGroups && filteredPostGroups.length > 0) { + filteredPostGroups[0].selected = true } - if (!filteredPosts || filteredPosts.length === 0) { + if (!filteredPostGroups || filteredPostGroups.length === 0) { return } else { return
{/* 文章列表 */} - {filteredPosts?.map((group, index) => )} + {filteredPostGroups?.map((group, index) => )}
} } diff --git a/themes/gitbook/index.js b/themes/gitbook/index.js index 0d059de6..05a42cc1 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 [filteredPosts, setFilteredPosts] = useState(allNavPages) + const [filteredPostGroups, setFilteredPostGroups] = useState(allNavPages) const showTocButton = post?.toc?.length > 1 useEffect(() => { - setFilteredPosts(allNavPages) + setFilteredPostGroups(allNavPages) }, [post]) return ( - +
@@ -71,7 +71,7 @@ const LayoutBase = (props) => { {slotLeft} {/* 所有文章列表 */} - +
@@ -143,7 +143,7 @@ const LayoutBase = (props) => {
} {/* 移动端导航抽屉 */} - + {/* 移动端底部导航栏 */} {/* */}