From 26373f1ddc630948b8f18bc3fb7da584c707b9bc Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Fri, 18 Aug 2023 17:15:26 +0800 Subject: [PATCH] =?UTF-8?q?gitbook=E5=B9=BF=E5=91=8A=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/gitbook/components/Catalog.js | 5 ++--- themes/gitbook/index.js | 5 ++--- themes/hexo/components/Catalog.js | 8 ++++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/themes/gitbook/components/Catalog.js b/themes/gitbook/components/Catalog.js index 5289c06c..ebee78ae 100644 --- a/themes/gitbook/components/Catalog.js +++ b/themes/gitbook/components/Catalog.js @@ -10,7 +10,6 @@ import { isBrowser } from '@/lib/utils' * @constructor */ const Catalog = ({ post }) => { - const tocIds = [] const toc = post?.toc // 同步选中目录事件 const [activeSection, setActiveSection] = useState(null) @@ -28,7 +27,7 @@ const Catalog = ({ post }) => { const actionSectionScrollSpy = useCallback(throttle(() => { const sections = document.getElementsByClassName('notion-h') let prevBBox = null - let currentSectionId = activeSection + let currentSectionId = null for (let i = 0; i < sections.length; ++i) { const section = sections[i] if (!section || !(section instanceof Element)) continue @@ -48,6 +47,7 @@ const Catalog = ({ post }) => { break } setActiveSection(currentSectionId) + const tocIds = post?.toc?.map((t) => uuidToId(t.id)) || [] const index = tocIds.indexOf(currentSectionId) || 0 if (isBrowser && tocIds?.length > 0) { for (const tocWrapper of document?.getElementsByClassName('toc-wrapper')) { @@ -66,7 +66,6 @@ const Catalog = ({ post }) => {