From 71106860bd4c97f67cf4f7cdffa0018c883c5d96 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Mon, 3 Jun 2024 18:02:23 +0800 Subject: [PATCH] =?UTF-8?q?gitbook=20=E5=B8=83=E5=B1=80=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/CatalogDrawerWrapper.js | 60 +++++++++++++++++++ themes/gitbook/components/FloatTocButton.js | 25 -------- themes/gitbook/components/Header.js | 2 +- themes/gitbook/components/JumpToTopButton.js | 24 ++++---- themes/gitbook/components/LogoBar.js | 12 ---- .../gitbook/components/MobileButtonCatalog.js | 27 +++++++++ .../gitbook/components/MobileButtonPageNav.js | 27 +++++++++ themes/gitbook/components/PageNavDrawer.js | 12 +++- themes/gitbook/components/TocDrawer.js | 34 ----------- themes/gitbook/index.js | 24 +++++--- themes/gitbook/style.js | 16 +++-- themes/nav/components/FloatButtonCatalog.js | 27 +++++++++ themes/nav/components/FloatTocButton.js | 25 -------- themes/nav/index.js | 4 +- 14 files changed, 195 insertions(+), 124 deletions(-) create mode 100644 themes/gitbook/components/CatalogDrawerWrapper.js delete mode 100644 themes/gitbook/components/FloatTocButton.js create mode 100644 themes/gitbook/components/MobileButtonCatalog.js create mode 100644 themes/gitbook/components/MobileButtonPageNav.js delete mode 100644 themes/gitbook/components/TocDrawer.js create mode 100644 themes/nav/components/FloatButtonCatalog.js delete mode 100755 themes/nav/components/FloatTocButton.js diff --git a/themes/gitbook/components/CatalogDrawerWrapper.js b/themes/gitbook/components/CatalogDrawerWrapper.js new file mode 100644 index 00000000..3b6ee8da --- /dev/null +++ b/themes/gitbook/components/CatalogDrawerWrapper.js @@ -0,0 +1,60 @@ +import { useGlobal } from '@/lib/global' +import { useGitBookGlobal } from '@/themes/gitbook' +import Catalog from './Catalog' + +/** + * 悬浮抽屉目录 + * @param toc + * @param post + * @returns {JSX.Element} + * @constructor + */ +const CatalogDrawerWrapper = ({ post, cRef }) => { + const { tocVisible, changeTocVisible } = useGitBookGlobal() + const { locale } = useGlobal() + const switchVisible = () => { + changeTocVisible(!tocVisible) + } + return ( + <> +
+ {/* 侧边菜单 */} +
+ {post && ( + <> +
+ {locale.COMMON.TABLE_OF_CONTENTS} + { + changeTocVisible(false) + }}> +
+
+ +
+ + )} +
+
+ {/* 背景蒙版 */} +
+ + ) +} +export default CatalogDrawerWrapper diff --git a/themes/gitbook/components/FloatTocButton.js b/themes/gitbook/components/FloatTocButton.js deleted file mode 100644 index 4215f447..00000000 --- a/themes/gitbook/components/FloatTocButton.js +++ /dev/null @@ -1,25 +0,0 @@ -import { useGitBookGlobal } from '@/themes/gitbook' - -/** - * 移动端悬浮目录按钮 - */ -export default function FloatTocButton () { - const { tocVisible, changeTocVisible } = useGitBookGlobal() - - const toggleToc = () => { - changeTocVisible(!tocVisible) - } - - return ( -
- -
- ) -} diff --git a/themes/gitbook/components/Header.js b/themes/gitbook/components/Header.js index 8dfb3735..8d538740 100644 --- a/themes/gitbook/components/Header.js +++ b/themes/gitbook/components/Header.js @@ -90,7 +90,7 @@ export default function Header(props) { {isOpen ? ( ) : ( - + )}
diff --git a/themes/gitbook/components/JumpToTopButton.js b/themes/gitbook/components/JumpToTopButton.js index 0afdbb6c..21b53733 100644 --- a/themes/gitbook/components/JumpToTopButton.js +++ b/themes/gitbook/components/JumpToTopButton.js @@ -1,4 +1,3 @@ - /** * 跳转到网页顶部 * 当屏幕下滑500像素后会出现该控件 @@ -9,15 +8,20 @@ */ const JumpToTopButton = ({ showPercent = false, percent, className }) => { return ( -
- { window.scrollTo({ top: 0, behavior: 'smooth' }) }} /> -
+
+ { + window.scrollTo({ top: 0, behavior: 'smooth' }) + }} + /> +
) } diff --git a/themes/gitbook/components/LogoBar.js b/themes/gitbook/components/LogoBar.js index c2d1c453..dfe3cadd 100644 --- a/themes/gitbook/components/LogoBar.js +++ b/themes/gitbook/components/LogoBar.js @@ -1,6 +1,5 @@ import LazyImage from '@/components/LazyImage' import { siteConfig } from '@/lib/config' -import { useGitBookGlobal } from '@/themes/gitbook' import Link from 'next/link' import CONFIG from '../config' @@ -11,19 +10,8 @@ import CONFIG from '../config' */ export default function LogoBar(props) { const { siteInfo } = props - const { pageNavVisible, changePageNavVisible } = useGitBookGlobal() - - const togglePageNavVisible = () => { - changePageNavVisible(!pageNavVisible) - } return (
-
- -
diff --git a/themes/gitbook/components/MobileButtonCatalog.js b/themes/gitbook/components/MobileButtonCatalog.js new file mode 100644 index 00000000..2c612894 --- /dev/null +++ b/themes/gitbook/components/MobileButtonCatalog.js @@ -0,0 +1,27 @@ +import { useGitBookGlobal } from '@/themes/gitbook' + +/** + * 移动端目录按钮 + */ +export default function MobileButtonCatalog() { + const { tocVisible, changeTocVisible } = useGitBookGlobal() + + const toggleToc = () => { + changeTocVisible(!tocVisible) + } + + return ( +
+ ) +} diff --git a/themes/gitbook/components/MobileButtonPageNav.js b/themes/gitbook/components/MobileButtonPageNav.js new file mode 100644 index 00000000..65a3c39a --- /dev/null +++ b/themes/gitbook/components/MobileButtonPageNav.js @@ -0,0 +1,27 @@ +import { useGitBookGlobal } from '@/themes/gitbook' + +/** + * 移动端文章导航按钮 + */ +export default function MobileButtonPageNav() { + const { pageNavVisible, changePageNavVisible } = useGitBookGlobal() + + const togglePageNavVisible = () => { + changePageNavVisible(!pageNavVisible) + } + + return ( + + ) +} diff --git a/themes/gitbook/components/PageNavDrawer.js b/themes/gitbook/components/PageNavDrawer.js index b5657d18..eb927762 100644 --- a/themes/gitbook/components/PageNavDrawer.js +++ b/themes/gitbook/components/PageNavDrawer.js @@ -1,3 +1,4 @@ +import { useGlobal } from '@/lib/global' import { useGitBookGlobal } from '@/themes/gitbook' import NavPostList from './NavPostList' @@ -11,6 +12,7 @@ import NavPostList from './NavPostList' const PageNavDrawer = props => { const { pageNavVisible, changePageNavVisible } = useGitBookGlobal() const { filteredNavPages } = props + const { locale } = useGlobal() const switchVisible = () => { changePageNavVisible(!pageNavVisible) @@ -24,7 +26,15 @@ const PageNavDrawer = props => { {/* 侧边菜单 */}
+ overflow-y-hidden shadow-card w-72 duration-200 fixed left-1 bottom-16 rounded py-2 bg-white dark:bg-hexo-black-gray`}> +
+ {locale.COMMON.ARTICLE} + { + changePageNavVisible(false) + }}> +
{/* 所有文章列表 */}
diff --git a/themes/gitbook/components/TocDrawer.js b/themes/gitbook/components/TocDrawer.js deleted file mode 100644 index 7b07044a..00000000 --- a/themes/gitbook/components/TocDrawer.js +++ /dev/null @@ -1,34 +0,0 @@ -import { useGitBookGlobal } from '@/themes/gitbook' -import Catalog from './Catalog' - -/** - * 悬浮抽屉目录 - * @param toc - * @param post - * @returns {JSX.Element} - * @constructor - */ -const TocDrawer = ({ post, cRef }) => { - const { tocVisible, changeTocVisible } = useGitBookGlobal() - const switchVisible = () => { - changeTocVisible(!tocVisible) - } - return <> -
- {/* 侧边菜单 */} -
- {post && <> -
- -
- } -
-
- {/* 背景蒙版 */} -
- -} -export default TocDrawer diff --git a/themes/gitbook/index.js b/themes/gitbook/index.js index 34c4f05d..9fe1682e 100644 --- a/themes/gitbook/index.js +++ b/themes/gitbook/index.js @@ -20,18 +20,19 @@ import ArticleInfo from './components/ArticleInfo' import { ArticleLock } from './components/ArticleLock' import BlogArchiveItem from './components/BlogArchiveItem' import Catalog from './components/Catalog' +import CatalogDrawerWrapper from './components/CatalogDrawerWrapper' import CategoryItem from './components/CategoryItem' -import FloatTocButton from './components/FloatTocButton' import Footer from './components/Footer' import Header from './components/Header' import InfoCard from './components/InfoCard' import JumpToTopButton from './components/JumpToTopButton' +import MobileButtonCatalog from './components/MobileButtonCatalog' +import MobileButtonPageNav from './components/MobileButtonPageNav' 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 TocDrawer from './components/TocDrawer' import CONFIG from './config' import { Style } from './style' @@ -211,6 +212,7 @@ const LayoutBase = props => {
+ {/* 桌面端目录 */} {slotRight} {router.route === '/' && ( @@ -235,12 +237,17 @@ const LayoutBase = props => { )} - {/* 移动端悬浮目录按钮 */} - {showTocButton && !tocVisible && ( -
- + {/* 移动端底部按钮 */} +
+
+
- )} + {showTocButton && ( +
+ +
+ )} +
{/* 移动端导航抽屉 */} @@ -366,7 +373,8 @@ const LayoutSlug = props => { )} - + {/* 文章目录 */} +
)} diff --git a/themes/gitbook/style.js b/themes/gitbook/style.js index 5e8eaa5a..904da2a7 100644 --- a/themes/gitbook/style.js +++ b/themes/gitbook/style.js @@ -5,14 +5,18 @@ * @returns */ const Style = () => { - return + .bottom-button-group { + box-shadow: 0px -3px 10px 0px rgba(0, 0, 0, 0.1); + } + `} + ) } export { Style } diff --git a/themes/nav/components/FloatButtonCatalog.js b/themes/nav/components/FloatButtonCatalog.js new file mode 100644 index 00000000..753451da --- /dev/null +++ b/themes/nav/components/FloatButtonCatalog.js @@ -0,0 +1,27 @@ +import { useNavGlobal } from '@/themes/nav' + +/** + * 移动端悬浮目录按钮 + */ +export default function FloatButtonCatalog() { + const { tocVisible, changeTocVisible } = useNavGlobal() + + const toggleToc = () => { + changeTocVisible(!tocVisible) + } + + return ( +
+ ) +} diff --git a/themes/nav/components/FloatTocButton.js b/themes/nav/components/FloatTocButton.js deleted file mode 100755 index d4ff317d..00000000 --- a/themes/nav/components/FloatTocButton.js +++ /dev/null @@ -1,25 +0,0 @@ -import { useNavGlobal } from '@/themes/nav' - -/** - * 移动端悬浮目录按钮 - */ -export default function FloatTocButton () { - const { tocVisible, changeTocVisible } = useNavGlobal() - - const toggleToc = () => { - changeTocVisible(!tocVisible) - } - - return ( - - ) -} diff --git a/themes/nav/index.js b/themes/nav/index.js index 54cea4b8..4a9bd724 100755 --- a/themes/nav/index.js +++ b/themes/nav/index.js @@ -25,7 +25,7 @@ import BlogArchiveItem from './components/BlogArchiveItem' import BlogPostCard from './components/BlogPostCard' import BlogPostListAll from './components/BlogPostListAll' import CategoryItem from './components/CategoryItem' -import FloatTocButton from './components/FloatTocButton' +import FloatButtonCatalog from './components/FloatButtonCatalog' import Footer from './components/Footer' import JumpToTopButton from './components/JumpToTopButton' import LogoBar from './components/LogoBar' @@ -187,7 +187,7 @@ const LayoutBase = props => { {/* 移动端悬浮目录按钮 */} {showTocButton && !tocVisible && (
- +
)}