diff --git a/themes/gitbook/components/PageNavDrawer.js b/themes/gitbook/components/PageNavDrawer.js
index 14846699db0..b5657d18ff6 100644
--- a/themes/gitbook/components/PageNavDrawer.js
+++ b/themes/gitbook/components/PageNavDrawer.js
@@ -8,7 +8,7 @@ import NavPostList from './NavPostList'
* @returns {JSX.Element}
* @constructor
*/
-const PageNavDrawer = (props) => {
+const PageNavDrawer = props => {
const { pageNavVisible, changePageNavVisible } = useGitBookGlobal()
const { filteredNavPages } = props
@@ -16,21 +16,29 @@ const PageNavDrawer = (props) => {
changePageNavVisible(!pageNavVisible)
}
- return <>
-
- {/* 侧边菜单 */}
-
+ return (
+ <>
+
+ {/* 侧边菜单 */}
+
- {/* 背景蒙版 */}
-
+
+
+ {/* 背景蒙版 */}
+
>
+ )
}
export default PageNavDrawer
diff --git a/themes/gitbook/components/TopNavBar.js b/themes/gitbook/components/TopNavBar.js
deleted file mode 100644
index c92df55d480..00000000000
--- a/themes/gitbook/components/TopNavBar.js
+++ /dev/null
@@ -1,73 +0,0 @@
-import LogoBar from './LogoBar'
-import { useRef, useState } from 'react'
-import Collapse from '@/components/Collapse'
-import { MenuBarMobile } from './MenuBarMobile'
-import { useGlobal } from '@/lib/global'
-import CONFIG from '../config'
-import { siteConfig } from '@/lib/config'
-import { MenuItemDrop } from './MenuItemDrop'
-import DarkModeButton from '@/components/DarkModeButton'
-
-/**
- * 顶部导航栏 + 菜单
- * @param {} param0
- * @returns
- */
-export default function TopNavBar(props) {
- const { className, customNav, customMenu } = props
- const [isOpen, changeShow] = useState(false)
- const collapseRef = useRef(null)
-
- const { locale } = useGlobal()
-
- const defaultLinks = [
- { icon: 'fas fa-th', name: locale.COMMON.CATEGORY, to: '/category', show: siteConfig('GITBOOK_MENU_CATEGORY', null, CONFIG) },
- { icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: siteConfig('GITBOOK_BOOK_MENU_TAG', null, CONFIG) },
- { icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', show: siteConfig('GITBOOK_MENU_ARCHIVE', null, CONFIG) },
- { icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: siteConfig('GITBOOK_MENU_SEARCH', null, CONFIG) }
- ]
-
- let links = defaultLinks.concat(customNav)
-
- const toggleMenuOpen = () => {
- changeShow(!isOpen)
- }
-
- // 如果 开启自定义菜单,则覆盖Page生成的菜单
- if (siteConfig('CUSTOM_MENU')) {
- links = customMenu
- }
-
- return (
-
-
- {/* 移动端折叠菜单 */}
-
-
- collapseRef.current?.updateCollapseHeight(param)} />
-
-
-
- {/* 导航栏菜单 */}
-
-
- {/* 左侧图标Logo */}
-
-
- {/* 折叠按钮、仅移动端显示 */}
-
-
- {/* 桌面端顶部菜单 */}
-
- {links && links?.map((link, index) => )}
-
-
-
-
- )
-}
diff --git a/themes/gitbook/index.js b/themes/gitbook/index.js
index 7d52f5a743d..68940b59902 100644
--- a/themes/gitbook/index.js
+++ b/themes/gitbook/index.js
@@ -1,41 +1,44 @@
'use client'
-import CONFIG from './config'
-import { useRouter } from 'next/router'
-import { useEffect, useState, createContext, useContext, useRef } from 'react'
-import { isBrowser } from '@/lib/utils'
-import Footer from './components/Footer'
-import InfoCard from './components/InfoCard'
-import RevolverMaps from './components/RevolverMaps'
-import TopNavBar from './components/TopNavBar'
-import SearchInput from './components/SearchInput'
-import { useGlobal } from '@/lib/global'
+import Comment from '@/components/Comment'
+import { AdSlot } from '@/components/GoogleAdsense'
import Live2D from '@/components/Live2D'
-import NavPostList from './components/NavPostList'
+import NotionIcon from '@/components/NotionIcon'
+import NotionPage from '@/components/NotionPage'
+import ShareBar from '@/components/ShareBar'
+import { siteConfig } from '@/lib/config'
+import { useGlobal } from '@/lib/global'
+import { isBrowser } from '@/lib/utils'
+import { Transition } from '@headlessui/react'
+import dynamic from 'next/dynamic'
+import Link from 'next/link'
+import { useRouter } from 'next/router'
+import { createContext, useContext, useEffect, useRef, useState } from 'react'
+import Announcement from './components/Announcement'
+import ArticleAround from './components/ArticleAround'
import ArticleInfo from './components/ArticleInfo'
+import { ArticleLock } from './components/ArticleLock'
+import BlogArchiveItem from './components/BlogArchiveItem'
import Catalog from './components/Catalog'
-import Announcement from './components/Announcement'
-import PageNavDrawer from './components/PageNavDrawer'
+import CategoryItem from './components/CategoryItem'
import FloatTocButton from './components/FloatTocButton'
-import { AdSlot } from '@/components/GoogleAdsense'
+import Footer from './components/Footer'
+import Header from './components/Header'
+import InfoCard from './components/InfoCard'
import JumpToTopButton from './components/JumpToTopButton'
-import ShareBar from '@/components/ShareBar'
-import CategoryItem from './components/CategoryItem'
+import NavPostList from './components/NavPostList'
+import PageNavDrawer from './components/PageNavDrawer'
+import RevolverMaps from './components/RevolverMaps'
+import SearchInput from './components/SearchInput'
import TagItemMini from './components/TagItemMini'
-import ArticleAround from './components/ArticleAround'
-import Comment from '@/components/Comment'
import TocDrawer from './components/TocDrawer'
-import NotionPage from '@/components/NotionPage'
-import { ArticleLock } from './components/ArticleLock'
-import { Transition } from '@headlessui/react'
+import CONFIG from './config'
import { Style } from './style'
-import BlogArchiveItem from './components/BlogArchiveItem'
-import Link from 'next/link'
-import dynamic from 'next/dynamic'
-import { siteConfig } from '@/lib/config'
-import NotionIcon from '@/components/NotionIcon'
-const AlgoliaSearchModal = dynamic(() => import('@/components/AlgoliaSearchModal'), { ssr: false })
+const AlgoliaSearchModal = dynamic(
+ () => import('@/components/AlgoliaSearchModal'),
+ { ssr: false }
+)
const WWAds = dynamic(() => import('@/components/WWAds'), { ssr: false })
// 主题全局变量
@@ -47,12 +50,14 @@ export const useGitBookGlobal = () => useContext(ThemeGlobalGitbook)
*/
function getNavPagesWithLatest(allNavPages, latestPosts, post) {
// localStorage 保存id和上次阅读时间戳: posts_read_time = {"${post.id}":"Date()"}
- const postReadTime = JSON.parse(localStorage.getItem('post_read_time') || '{}');
+ const postReadTime = JSON.parse(
+ localStorage.getItem('post_read_time') || '{}'
+ )
if (post) {
- postReadTime[post.id] = new Date().getTime();
+ postReadTime[post.id] = new Date().getTime()
}
// 更新
- localStorage.setItem('post_read_time', JSON.stringify(postReadTime));
+ localStorage.setItem('post_read_time', JSON.stringify(postReadTime))
return allNavPages?.map(item => {
const res = {
@@ -67,12 +72,14 @@ function getNavPagesWithLatest(allNavPages, latestPosts, post) {
lastEditedDate: item.lastEditedDate
}
// 属于最新文章通常6篇 && (无阅读记录 || 最近更新时间大于上次阅读时间)
- if (latestPosts.some(post => post.id === item.id) &&
- (!postReadTime[item.id] || postReadTime[item.id] < new Date(item.lastEditedDate).getTime())
+ if (
+ latestPosts.some(post => post.id === item.id) &&
+ (!postReadTime[item.id] ||
+ postReadTime[item.id] < new Date(item.lastEditedDate).getTime())
) {
- return { ...res, isLatest: true };
+ return { ...res, isLatest: true }
} else {
- return res;
+ return res
}
})
}
@@ -83,8 +90,16 @@ function getNavPagesWithLatest(allNavPages, latestPosts, post) {
* @returns {JSX.Element}
* @constructor
*/
-const LayoutBase = (props) => {
- const { children, post, allNavPages, latestPosts, slotLeft, slotRight, slotTop } = props
+const LayoutBase = props => {
+ const {
+ children,
+ post,
+ allNavPages,
+ latestPosts,
+ slotLeft,
+ slotRight,
+ slotTop
+ } = props
const { onLoading, fullWidth } = useGlobal()
const router = useRouter()
const [tocVisible, changeTocVisible] = useState(false)
@@ -99,110 +114,140 @@ const LayoutBase = (props) => {
}, [router])
return (
-
-
-
-
-
-
- {/* 顶部导航栏 */}
-
-
-
-
- {/* 左侧推拉抽屉 */}
- {fullWidth
- ? null
- : (
-
- {slotLeft}
-
-
- {/* 所有文章列表 */}
-
-
-
-
-
-
-
-
-
) }
-
-
-
-
- {slotTop}
-
-
-
- {children}
-
-
- {/* Google广告 */}
-
-
-
- {/* 回顶按钮 */}
-
-
-
- {/* 底部 */}
-
-
-
-
-
- {/* 右侧侧推拉抽屉 */}
- {fullWidth
- ? null
- :
-
-
-
-
-
- {slotRight}
- {router.route === '/' && <>
-
- {siteConfig('GITBOOK_WIDGET_REVOLVER_MAPS', null, CONFIG) === 'true' &&
}
-
- >}
- {/* gitbook主题首页只显示公告 */}
-
-
-
-
-
-
-
-
}
-
-
-
- {/* 移动端悬浮目录按钮 */}
- {showTocButton && !tocVisible &&
-
-
}
-
- {/* 移动端导航抽屉 */}
-
-
- {/* 移动端底部导航栏 */}
- {/*
*/}
+
+
+
+
+
+
+ {/* 顶部导航栏 */}
+
+
+
+ {/* 左侧推拉抽屉 */}
+ {fullWidth ? null : (
+
+
+ {slotLeft}
+
+
+ {/* 所有文章列表 */}
+
+
+
+
+
+
+
+
+ )}
+
+
+
+ {slotTop}
+
+
+
+ {children}
+
+
+ {/* Google广告 */}
+
+
+
+ {/* 回顶按钮 */}
+
+
+
+ {/* 底部 */}
+
+
+
+
+
+ {/* 右侧侧推拉抽屉 */}
+ {fullWidth ? null : (
+
+
+
+
+
+
+ {slotRight}
+ {router.route === '/' && (
+ <>
+
+ {siteConfig(
+ 'GITBOOK_WIDGET_REVOLVER_MAPS',
+ null,
+ CONFIG
+ ) === 'true' &&
}
+
+ >
+ )}
+ {/* gitbook主题首页只显示公告 */}
+
+
+
+
+
-
+ )}
+
+
+ {/* 移动端悬浮目录按钮 */}
+ {showTocButton && !tocVisible && (
+
+
+
+ )}
+
+ {/* 移动端导航抽屉 */}
+
+
+ {/* 移动端底部导航栏 */}
+ {/*
*/}
+
+
)
}
@@ -212,7 +257,7 @@ const LayoutBase = (props) => {
* @param {*} props
* @returns
*/
-const LayoutIndex = (props) => {
+const LayoutIndex = props => {
const router = useRouter()
useEffect(() => {
router.push(siteConfig('GITBOOK_INDEX_PAGE', null, CONFIG)).then(() => {
@@ -221,8 +266,13 @@ const LayoutIndex = (props) => {
if (isBrowser) {
const article = document.getElementById('notion-article')
if (!article) {
- console.log('请检查您的Notion数据库中是否包含此slug页面: ', siteConfig('GITBOOK_INDEX_PAGE', null, CONFIG))
- const containerInner = document.querySelector('#theme-gitbook #container-inner')
+ console.log(
+ '请检查您的Notion数据库中是否包含此slug页面: ',
+ siteConfig('GITBOOK_INDEX_PAGE', null, CONFIG)
+ )
+ const containerInner = document.querySelector(
+ '#theme-gitbook #container-inner'
+ )
const newHTML = `
配置有误
请在您的notion中添加一个slug为${siteConfig('GITBOOK_INDEX_PAGE', null, CONFIG)}的文章
`
containerInner?.insertAdjacentHTML('afterbegin', newHTML)
}
@@ -240,7 +290,7 @@ const LayoutIndex = (props) => {
* @param {*} props
* @returns
*/
-const LayoutPostList = (props) => {
+const LayoutPostList = props => {
return <>>
}
@@ -249,59 +299,76 @@ const LayoutPostList = (props) => {
* @param {*} props
* @returns
*/
-const LayoutSlug = (props) => {
+const LayoutSlug = props => {
const { post, prev, next, lock, validPassword } = props
const router = useRouter()
useEffect(() => {
// 404
if (!post) {
- setTimeout(() => {
- if (isBrowser) {
- const article = document.getElementById('notion-article')
- if (!article) {
- router.push('/404').then(() => {
- console.warn('找不到页面', router.asPath)
- })
+ setTimeout(
+ () => {
+ if (isBrowser) {
+ const article = document.getElementById('notion-article')
+ if (!article) {
+ router.push('/404').then(() => {
+ console.warn('找不到页面', router.asPath)
+ })
+ }
}
- }
- }, siteConfig('POST_WAITING_TIME_FOR_404') * 1000)
+ },
+ siteConfig('POST_WAITING_TIME_FOR_404') * 1000
+ )
}
}, [post])
return (
- <>
- {/* 文章锁 */}
- {lock &&
}
-
- {!lock &&
-
- {/* title */}
-
{siteConfig('POST_TITLE_ICON') && }{post?.title}
-
- {/* Notion文章主体 */}
- {post && (
-
-
- {/* 分享 */}
-
- {/* 文章分类和标签信息 */}
-
- {siteConfig('POST_DETAIL_CATEGORY', null, CONFIG) && post?.category &&
}
-
- {siteConfig('POST_DETAIL_TAG', null, CONFIG) && post?.tagItems?.map(tag => )}
-
-
+ <>
+ {/* 文章锁 */}
+ {lock && }
+
+ {!lock && (
+
+ {/* title */}
+
+ {siteConfig('POST_TITLE_ICON') && (
+
+ )}
+ {post?.title}
+
+
+ {/* Notion文章主体 */}
+ {post && (
+
+
+
+ {/* 分享 */}
+
+ {/* 文章分类和标签信息 */}
+
+ {siteConfig('POST_DETAIL_CATEGORY', null, CONFIG) &&
+ post?.category &&
}
+
+ {siteConfig('POST_DETAIL_TAG', null, CONFIG) &&
+ post?.tagItems?.map(tag => (
+
+ ))}
+
+
- {post?.type === 'Post' && }
+ {post?.type === 'Post' && (
+
+ )}
-
-
+
+
-
- )}
+
+
+ )}
-
-
}
- >
+
+
+ )}
+ >
)
}
@@ -311,7 +378,7 @@ const LayoutSlug = (props) => {
* @param {*} props
* @returns
*/
-const LayoutSearch = (props) => {
+const LayoutSearch = props => {
return <>>
}
@@ -321,91 +388,111 @@ const LayoutSearch = (props) => {
* @param {*} props
* @returns
*/
-const LayoutArchive = (props) => {
+const LayoutArchive = props => {
const { archivePosts } = props
- return <>
-
- {Object.keys(archivePosts)?.map(archiveTitle => )}
-
- >
+ return (
+ <>
+
+ {Object.keys(archivePosts)?.map(archiveTitle => (
+
+ ))}
+
+ >
+ )
}
/**
* 404
*/
const Layout404 = props => {
- return <>
-
404 Not found.
+ return (
+ <>
+
+ 404 Not found.
+
>
+ )
}
/**
* 分类列表
*/
-const LayoutCategoryIndex = (props) => {
+const LayoutCategoryIndex = props => {
const { categoryOptions } = props
const { locale } = useGlobal()
- return <>
-
-
- {locale.COMMON.CATEGORY}:
-
-
- {categoryOptions?.map(category => {
- return (
-
-
- {category.name}({category.count})
-
-
- )
- })}
+ return (
+ <>
+
+
+
+ {locale.COMMON.CATEGORY}:
+
+
+ {categoryOptions?.map(category => {
+ return (
+
+
+
+ {category.name}({category.count})
-
- >
+
+ )
+ })}
+
+
+ >
+ )
}
/**
* 标签列表
*/
-const LayoutTagIndex = (props) => {
+const LayoutTagIndex = props => {
const { tagOptions } = props
const { locale } = useGlobal()
- return <>
-
-
-
- {locale.COMMON.TAGS}:
-
-
-
- >
+ return (
+ <>
+
+
+
+ {locale.COMMON.TAGS}:
+
+
+
+ >
+ )
}
export {
- CONFIG as THEME_CONFIG,
+ Layout404,
+ LayoutArchive,
LayoutBase,
+ LayoutCategoryIndex,
LayoutIndex,
+ LayoutPostList,
LayoutSearch,
- LayoutArchive,
LayoutSlug,
- Layout404,
- LayoutPostList,
- LayoutCategoryIndex,
- LayoutTagIndex
+ LayoutTagIndex,
+ CONFIG as THEME_CONFIG
}