-
{locale.COMMON.TABLE_OF_CONTENTS}
-
-
+ return (
+
+
+
+ {locale.COMMON.TABLE_OF_CONTENTS}
+
+
+
+
+
-
-
-
-
-
+ )
}
export default Catalog
diff --git a/themes/medium/components/Catalog.js b/themes/medium/components/Catalog.js
index cdb65fe4..cb19ae91 100644
--- a/themes/medium/components/Catalog.js
+++ b/themes/medium/components/Catalog.js
@@ -1,6 +1,6 @@
-import { useCallback, useEffect, useRef, useState } from 'react'
import throttle from 'lodash.throttle'
import { uuidToId } from 'notion-utils'
+import { useCallback, useEffect, useRef, useState } from 'react'
import Progress from './Progress'
/**
@@ -27,65 +27,73 @@ const Catalog = ({ toc }) => {
}, [])
const throttleMs = 200
- const actionSectionScrollSpy = useCallback(throttle(() => {
- const sections = document.getElementsByClassName('notion-h')
- let prevBBox = null
- let currentSectionId = activeSection
- for (let i = 0; i < sections.length; ++i) {
- const section = sections[i]
- if (!section || !(section instanceof Element)) continue
- if (!currentSectionId) {
- currentSectionId = section.getAttribute('data-id')
+ const actionSectionScrollSpy = useCallback(
+ throttle(() => {
+ const sections = document.getElementsByClassName('notion-h')
+ let prevBBox = null
+ let currentSectionId = activeSection
+ for (let i = 0; i < sections.length; ++i) {
+ const section = sections[i]
+ if (!section || !(section instanceof Element)) continue
+ if (!currentSectionId) {
+ currentSectionId = section.getAttribute('data-id')
+ }
+ const bbox = section.getBoundingClientRect()
+ const prevHeight = prevBBox ? bbox.top - prevBBox.bottom : 0
+ const offset = Math.max(150, prevHeight / 4)
+ // GetBoundingClientRect returns values relative to viewport
+ if (bbox.top - offset < 0) {
+ currentSectionId = section.getAttribute('data-id')
+ prevBBox = bbox
+ continue
+ }
+ // No need to continue loop, if last element has been detected
+ break
}
- const bbox = section.getBoundingClientRect()
- const prevHeight = prevBBox ? bbox.top - prevBBox.bottom : 0
- const offset = Math.max(150, prevHeight / 4)
- // GetBoundingClientRect returns values relative to viewport
- if (bbox.top - offset < 0) {
- currentSectionId = section.getAttribute('data-id')
- prevBBox = bbox
- continue
- }
- // No need to continue loop, if last element has been detected
- break
- }
- setActiveSection(currentSectionId)
- const index = tocIds.indexOf(currentSectionId) || 0
- tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' })
- }, throttleMs))
+ setActiveSection(currentSectionId)
+ const index = tocIds.indexOf(currentSectionId) || 0
+ tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' })
+ }, throttleMs)
+ )
// 无目录就直接返回空
if (!toc || toc.length < 1) {
return <>>
}
- return
-
-
+ return (
+
+
+
+
+
-
-
-
-
+ )
}
export default Catalog
diff --git a/themes/nav/components/Catalog.js b/themes/nav/components/Catalog.js
index cf8e606f..70f6f771 100755
--- a/themes/nav/components/Catalog.js
+++ b/themes/nav/components/Catalog.js
@@ -1,7 +1,7 @@
-import { useCallback, useEffect, useState } from 'react'
+import { isBrowser } from '@/lib/utils'
import throttle from 'lodash.throttle'
import { uuidToId } from 'notion-utils'
-import { isBrowser } from '@/lib/utils'
+import { useCallback, useEffect, useState } from 'react'
/**
* 目录导航组件
@@ -24,66 +24,76 @@ const Catalog = ({ post }) => {
}, [post])
const throttleMs = 200
- const actionSectionScrollSpy = useCallback(throttle(() => {
- const sections = document.getElementsByClassName('notion-h')
- let prevBBox = null
- let currentSectionId = null
- for (let i = 0; i < sections.length; ++i) {
- const section = sections[i]
- if (!section || !(section instanceof Element)) continue
- if (!currentSectionId) {
- currentSectionId = section.getAttribute('data-id')
+ const actionSectionScrollSpy = useCallback(
+ throttle(() => {
+ const sections = document.getElementsByClassName('notion-h')
+ let prevBBox = null
+ let currentSectionId = null
+ for (let i = 0; i < sections.length; ++i) {
+ const section = sections[i]
+ if (!section || !(section instanceof Element)) continue
+ if (!currentSectionId) {
+ currentSectionId = section.getAttribute('data-id')
+ }
+ const bbox = section.getBoundingClientRect()
+ const prevHeight = prevBBox ? bbox.top - prevBBox.bottom : 0
+ const offset = Math.max(150, prevHeight / 4)
+ // GetBoundingClientRect returns values relative to viewport
+ if (bbox.top - offset < 0) {
+ currentSectionId = section.getAttribute('data-id')
+ prevBBox = bbox
+ continue
+ }
+ // No need to continue loop, if last element has been detected
+ break
}
- const bbox = section.getBoundingClientRect()
- const prevHeight = prevBBox ? bbox.top - prevBBox.bottom : 0
- const offset = Math.max(150, prevHeight / 4)
- // GetBoundingClientRect returns values relative to viewport
- if (bbox.top - offset < 0) {
- currentSectionId = section.getAttribute('data-id')
- prevBBox = bbox
- continue
+ 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'
+ )) {
+ tocWrapper?.scrollTo({ top: 28 * index, behavior: 'smooth' })
+ }
}
- // No need to continue loop, if last element has been detected
- 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')) {
- tocWrapper?.scrollTo({ top: 28 * index, behavior: 'smooth' })
- }
- }
- }, throttleMs))
+ }, throttleMs)
+ )
// 无目录就直接返回空
if (!toc || toc.length < 1) {
return null
}
- return <>
-
-
-
- >
+ return (
+ <>
+
+ >
+ )
}
export default Catalog
diff --git a/themes/next/components/Toc.js b/themes/next/components/Toc.js
index 388d3fa1..4316a25e 100644
--- a/themes/next/components/Toc.js
+++ b/themes/next/components/Toc.js
@@ -77,7 +77,7 @@ const Toc = ({ toc }) => {
key={id}
href={`#${id}`}
className={`notion-table-of-contents-item duration-300 transform font-light
- notion-table-of-contents-item-indent-level-${tocItem.indentLevel} `}>
+ notion-table-of-contents-item-indent-level-${tocItem.indentLevel} catalog-item `}>
{
key={id}
href={`#${id}`}
className={`${activeSection === id && 'dark:border-white border-gray-800 text-gray-800 font-bold'} hover:font-semibold border-l pl-4 block hover:text-gray-800 border-lduration-300 transform dark:text-gray-400 dark:border-gray-400
- notion-table-of-contents-item-indent-level-${tocItem.indentLevel} `}>
+ notion-table-of-contents-item-indent-level-${tocItem.indentLevel} catalog-item `}>
{
key={id}
href={`#${id}`}
className={`${activeSection === id && 'dark:border-white border-red-700 text-red-700 font-bold'} hover:font-semibold border-l pl-4 block hover:text-red-600 border-lduration-300 transform dark:text-red-400 dark:border-red-400
- notion-table-of-contents-item-indent-level-${tocItem.indentLevel} `}>
+ notion-table-of-contents-item-indent-level-${tocItem.indentLevel} catalog-item `}>