fix gitbook

This commit is contained in:
tangly1024
2023-07-08 10:59:14 +08:00
parent 9be8820cff
commit c06e09d17a
4 changed files with 16 additions and 17 deletions

View File

@@ -30,14 +30,14 @@ const LayoutBase = (props) => {
const { children, meta, post, allNavPages, slotLeft, slotRight, slotTop } = props
const [tocVisible, changeTocVisible] = useState(false)
const [pageNavVisible, changePageNavVisible] = useState(false)
const [filterPosts, setFilterPosts] = useState(allNavPages)
const [filteredPostGroups, setFilteredPostGroups] = useState(allNavPages)
const { onLoading } = useGlobal()
const router = useRouter()
const showTocButton = post?.toc?.length > 1
useEffect(() => {
setFilterPosts(allNavPages)
setFilteredPostGroups(allNavPages)
}, [post])
const LoadingCover = <div id='cover-loading' className={`${onLoading ? 'z-50 opacity-50' : '-z-10 opacity-0'} pointer-events-none transition-all duration-300`}>
@@ -47,10 +47,10 @@ const LayoutBase = (props) => {
</div>
return (
<ThemeGlobalMedium.Provider value={{ tocVisible, changeTocVisible, filterPosts, setFilterPosts, allNavPages, pageNavVisible, changePageNavVisible }}>
<CommonHead meta={meta} />
<ThemeGlobalMedium.Provider value={{ tocVisible, changeTocVisible, filteredPostGroups, setFilteredPostGroups, allNavPages, pageNavVisible, changePageNavVisible }}>
<div id='theme-medium' className='bg-white dark:bg-hexo-black-gray w-full h-full min-h-screen justify-center dark:text-gray-300'>
<CommonHead meta={meta} />
{/* 顶部导航栏 */}
<TopNavBar {...props} />
@@ -64,7 +64,7 @@ const LayoutBase = (props) => {
<SearchInput className='my-3 rounded-md' />
{/* 所有文章列表 */}
<NavPostList posts={filterPosts} />
<NavPostList {...props} filteredPostGroups={filteredPostGroups} />
<div className='mt-2'>
<Footer {...props} />
@@ -90,7 +90,7 @@ const LayoutBase = (props) => {
{/* 底部 */}
<div className='md:hidden'>
<Footer {...props}/>
<Footer {...props} />
</div>
<div className='text-center'>
<AdSlot type='native' />

View File

@@ -27,8 +27,7 @@ export const LayoutIndex = (props) => {
}, 7 * 1000)
})
}, [])
return <LayoutBase {...props}>
</LayoutBase>
return <LayoutBase {...props}/>
}
export default LayoutIndex

View File

@@ -1,6 +1,7 @@
import NavPostListEmpty from './NavPostListEmpty'
import { useRouter } from 'next/router'
import NavPostItem from './NavPostItem'
import { deepClone } from '@/lib/utils'
/**
* 博客列表滚动分页
@@ -10,13 +11,12 @@ import NavPostItem from './NavPostItem'
* @constructor
*/
const NavPostList = (props) => {
const { posts = [], currentSearch } = props
const filteredPosts = Object.assign(posts)
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 +29,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) {
return <NavPostListEmpty currentSearch={currentSearch} />
if (!filteredPostGroups || filteredPostGroups.length === 0) {
return <NavPostListEmpty />
} else {
return <div className='w-full flex-grow'>
{/* 文章列表 */}
{filteredPosts?.map((group, index) => <NavPostItem key={index} group={group} onHeightChange={props.onHeightChange}/>)}
{filteredPostGroups?.map((group, index) => <NavPostItem key={index} group={group} onHeightChange={props.onHeightChange}/>)}
</div>
}
}

View File

@@ -8,7 +8,7 @@ import NavPostList from './NavPostList'
* @returns {JSX.Element}
* @constructor
*/
const PageNavDrawer = ({ post, cRef }) => {
const PageNavDrawer = (props) => {
const { pageNavVisible, changePageNavVisible, filterPosts } = useGitBookGlobal()
const switchVisible = () => {
changePageNavVisible(!pageNavVisible)