diff --git a/lib/notion/getAllPosts.js b/lib/notion/getAllPosts.js index 246c5c3f..ffde6490 100644 --- a/lib/notion/getAllPosts.js +++ b/lib/notion/getAllPosts.js @@ -9,10 +9,10 @@ import { delCacheData } from '@/lib/cache/cache_manager' * 获取所有文章列表 * @param notionPageData * @param from - * @param includePage 是否包含Page类型 + * @param pageType 页面类型数组 ['Post','Page'] * @returns {Promise<*[]>} */ -export async function getAllPosts ({ notionPageData, from, includePage = false }) { +export async function getAllPosts ({ notionPageData, from, pageType }) { if (!notionPageData) { notionPageData = await getNotionPageData({ from }) } @@ -31,8 +31,8 @@ export async function getAllPosts ({ notionPageData, from, includePage = false } const id = pageIds[i] const properties = (await getPageProperties(id, pageBlock, schema)) || null properties.slug = properties.slug ?? properties.id - properties.createdTime = new Date(pageBlock[id].value?.created_time).toString() - properties.lastEditedTime = new Date(pageBlock[id].value?.last_edited_time).toString() + properties.createdTime = new Date(pageBlock[id].value?.created_time).toString() // FIXME 似乎没有created_time 字段了 + properties.lastEditedTime = new Date(pageBlock[id].value?.last_edited_time).toString() // FIXME 似乎没有created_time 字段了 properties.fullWidth = pageBlock[id].value?.format?.page_full_width ?? false properties.page_cover = getPostCover(id, pageBlock) ?? null properties.content = pageBlock[id].value?.content ?? [] @@ -45,19 +45,7 @@ export async function getAllPosts ({ notionPageData, from, includePage = false } // remove all the the items doesn't meet requirements const posts = data.filter(post => { - if (includePage) { - return ( - post.title && post.slug && - post?.status?.[0] === 'Published' && - (post?.type?.[0] === 'Post' || post?.type?.[0] === 'Page') - ) - } else { - return ( - post.title && post.slug && - post?.status?.[0] === 'Published' && - (post?.type?.[0] === 'Post') - ) - } + return post.title && post?.status?.[0] === 'Published' && pageType.indexOf(post?.type?.[0]) > -1 }) if (!posts || posts.length === 0) { @@ -65,6 +53,7 @@ export async function getAllPosts ({ notionPageData, from, includePage = false } const cacheKey = 'page_block_' + BLOG.NOTION_PAGE_ID await delCacheData(cacheKey) } + // Sort by date if (BLOG.POSTS_SORT_BY === 'date') { posts.sort((a, b) => { @@ -84,3 +73,19 @@ function getPostCover (id, block) { if (pageCover.startsWith('http')) return defaultMapImageUrl(pageCover, block[id].value) } } + +/** + * 获取博文总数 + * @param {*} param0 + * @returns + */ +export async function getAllPostCount ({ notionPageData, from }) { + if (!notionPageData) { + notionPageData = await getNotionPageData({ from }) + } + if (!notionPageData) { + return [] + } + const allPosts = await getAllPosts({ notionPageData, from, pageType: ['Post'] }) + return allPosts?.length || 0 +} diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 61a5a934..4873cf9c 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -3,7 +3,7 @@ import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager' import { getPostBlocks } from '@/lib/notion/getPostBlocks' import { idToUuid } from 'notion-utils' import { getAllCategories } from './getAllCategories' -import { getAllPosts } from './getAllPosts' +import { getAllPosts, getAllPostCount } from './getAllPosts' import { getAllTags } from './getAllTags' /** @@ -12,23 +12,29 @@ import { getAllTags } from './getAllTags' * @param {*} from * @param latestPostCount 截取最新文章数量 * @param tagsCount 截取标签数量 - * @param includePage 是否包含PAGE类型 - * @returns {} - * allPosts 所有博客 - * categories 所有分类 - * tags 所有标签 + * @param pageType 过滤的文章类型,数组格式 ['Page','Post'] + * @returns { + allPosts, 所有博客 + latestPosts, + categories, 所有分类 + postCount, + customNav, 自定义导航菜单 + tags 所有标签 + } + * */ export async function getGlobalNotionData ({ pageId = BLOG.NOTION_PAGE_ID, from, latestPostCount = 5, tagsCount = 16, - includePage + pageType = ['Post'] }) { const notionPageData = await getNotionPageData({ pageId, from }) const tagOptions = notionPageData.tagOptions - const allPosts = await getAllPosts({ notionPageData, from, includePage }) - const postCount = allPosts?.length + const allPosts = await getAllPosts({ notionPageData, from, pageType }) + const postCount = await getAllPostCount({ notionPageData, from }) + const customNav = await getCustomNav({ notionPageData }) const categories = await getAllCategories(allPosts) const tags = await getAllTags({ allPosts, tagOptions, sliceCount: tagsCount }) // 深拷贝 @@ -47,6 +53,7 @@ export async function getGlobalNotionData ({ latestPosts, categories, postCount, + customNav, tags } } @@ -73,6 +80,23 @@ export async function getNotionPageData ({ pageId, from }) { return pageRecordMap } +async function getCustomNav ({ notionPageData }) { + if (!notionPageData) { + notionPageData = await getNotionPageData({ from: 'custom-nav' }) + } + if (!notionPageData) { + return [] + } + const allPage = await getAllPosts({ notionPageData, from: 'custom-nav', pageType: ['Page'] }) + const customNav = [] + if (allPage && allPage.length > 0) { + allPage.forEach(p => { + customNav.push({ icon: p.icon || null, name: p.title, to: '/' + p.slug, show: true }) + }) + } + return customNav +} + /** * 获取标签选项 * @param schema diff --git a/lib/rss.js b/lib/rss.js index f02a5a0b..9400629f 100644 --- a/lib/rss.js +++ b/lib/rss.js @@ -4,14 +4,14 @@ import BLOG from '@/blog.config' export function generateRss (posts) { const year = new Date().getFullYear() const feed = new Feed({ - TITLE: BLOG.TITLE, - DESCRIPTION: BLOG.DESCRIPTION, + title: BLOG.TITLE, + description: BLOG.DESCRIPTION, id: `${BLOG.LINK}/${BLOG.PATH}`, - LINK: `${BLOG.LINK}/${BLOG.PATH}`, + link: `${BLOG.LINK}/${BLOG.PATH}`, language: BLOG.LANG, favicon: `${BLOG.LINK}/favicon.png`, copyright: `All rights reserved ${year}, ${BLOG.AUTHOR}`, - AUTHOR: { + author: { name: BLOG.AUTHOR, email: BLOG.CONTACT_EMAIL, link: BLOG.LINK diff --git a/package.json b/package.json index 172ff577..9a7a661c 100644 --- a/package.json +++ b/package.json @@ -19,10 +19,6 @@ "post-build": "next-sitemap --config next-sitemap.config.js" }, "dependencies": { - "@fortawesome/fontawesome-svg-core": "^1.2.36", - "@fortawesome/free-brands-svg-icons": "^5.15.4", - "@fortawesome/free-solid-svg-icons": "^5.15.4", - "@fortawesome/react-fontawesome": "^0.1.16", "@popperjs/core": "^2.9.3", "animate.css": "^4.1.1", "axios": ">=0.21.1", @@ -33,15 +29,15 @@ "lodash.throttle": "^4.1.1", "memory-cache": "^0.2.0", "next": "^12.0.5", - "notion-client": "4.14.1", - "notion-utils": "4.14.1", + "notion-client": "4.16.0", + "notion-utils": "4.16.0", "preact": "^10.5.15", "qrcode.react": "^1.0.1", "react": "17.0.2", "react-cookies": "^0.1.1", "react-cusdis": "^2.1.3", "react-dom": "17.0.2", - "react-notion-x": "4.14.2", + "react-notion-x": "4.16.0", "smoothscroll-polyfill": "^0.4.4", "typed.js": "^2.0.12", "use-ackee": "^3.0.0" diff --git a/pages/[slug].js b/pages/[slug].js new file mode 100644 index 00000000..4d1a13d9 --- /dev/null +++ b/pages/[slug].js @@ -0,0 +1,58 @@ +import BLOG from '@/blog.config' +import { getPostBlocks } from '@/lib/notion' +import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { LayoutSlug } from '@/themes' +import Custom404 from '@/pages/404' + +/** + * 根据notion的slug访问页面,针对类型为Page的页面 + * @param {*} props + * @returns + */ +const Slug = (props) => { + if (!props.post) { + return + } + return +} + +export async function getStaticPaths () { + if (!BLOG.isProd) { + return { + paths: [], + fallback: true + } + } + + const from = 'slug-paths' + const { allPosts } = await getGlobalNotionData({ from, pageType: ['Page'] }) + return { + paths: allPosts.map(row => ({ params: { slug: row.slug } })), + fallback: true + } +} + +export async function getStaticProps ({ params: { slug } }) { + const from = `slug-props-${slug}` + const { allPosts, categories, tags, postCount, latestPosts, customNav } = await getGlobalNotionData({ from, pageType: ['Page'] }) + const post = allPosts.find(p => p.slug === slug) + if (!post) { + return { props: {}, revalidate: 1 } + } + + post.blockMap = await getPostBlocks(post.id, 'slug') + + return { + props: { + post, + tags, + categories, + postCount, + latestPosts, + customNav + }, + revalidate: 1 + } +} + +export default Slug diff --git a/pages/_app.js b/pages/_app.js index 43aeb3f2..98c5abc1 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -14,9 +14,6 @@ import 'prismjs/themes/prism-okaidia.css' import 'katex/dist/katex.min.css' import dynamic from 'next/dynamic' import { GlobalContextProvider } from '@/lib/global' -import { config } from '@fortawesome/fontawesome-svg-core' -import '@fortawesome/fontawesome-svg-core/styles.css' -config.autoAddCss = false const Ackee = dynamic(() => import('@/components/Ackee'), { ssr: false }) const Gtag = dynamic(() => import('@/components/Gtag'), { ssr: false }) @@ -30,6 +27,7 @@ const MyApp = ({ Component, pageProps }) => { {BLOG.ANALYTICS_GOOGLE_ID && } {JSON.parse(BLOG.ANALYTICS_BUSUANZI_ENABLE) && } {BLOG.ADSENSE_GOOGLE_ID && } + ) diff --git a/pages/about.js b/pages/about.js deleted file mode 100644 index 895a94f3..00000000 --- a/pages/about.js +++ /dev/null @@ -1,60 +0,0 @@ -import { getPostBlocks } from '@/lib/notion' -import { getGlobalNotionData } from '@/lib/notion/getNotionData' -import Custom404 from '@/pages/404' -import React from 'react' -import { LayoutSlug } from '@/themes' - -/** - * 关于页面,默认取notion中slug为about的文章 - * @param {*} props - * @returns - */ -const About = (props) => { - if (!props.post) { - return - } - return -} - -export async function getStaticProps () { - const from = 'about-props' - const { - allPosts, - categories, - tags, - postCount, - latestPosts - } = await getGlobalNotionData({ - from, - includePage: true - }) - const post = allPosts.find(p => p.slug === 'about') - - if (!post) { - return { - props: {}, - revalidate: 1 - } - } - - post.blockMap = await getPostBlocks(post.id, 'slug') - - const index = allPosts.indexOf(post) - const prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0] - const next = allPosts.slice(index + 1, index + 2)[0] ?? allPosts[0] - - return { - props: { - post, - tags, - prev, - next, - categories, - postCount, - latestPosts - }, - revalidate: 1 - } -} - -export default About diff --git a/pages/article/[slug].js b/pages/article/[slug].js index bdc6d706..d79e0cc7 100644 --- a/pages/article/[slug].js +++ b/pages/article/[slug].js @@ -13,7 +13,7 @@ const Slug = (props) => { if (!props.post) { return } - return + return } export async function getStaticPaths () { @@ -25,7 +25,7 @@ export async function getStaticPaths () { } const from = 'slug-paths' - const { allPosts } = await getGlobalNotionData({ from, includePage: true }) + const { allPosts } = await getGlobalNotionData({ from }) return { paths: allPosts.map(row => ({ params: { slug: row.slug } })), fallback: true @@ -34,8 +34,8 @@ export async function getStaticPaths () { export async function getStaticProps ({ params: { slug } }) { const from = `slug-props-${slug}` - const { allPosts, categories, tags, postCount, latestPosts } = - await getGlobalNotionData({ from, includePage: true }) + const { customNav, allPosts, categories, tags, postCount, latestPosts } = + await getGlobalNotionData({ from, pageType: ['Post'] }) const post = allPosts.find(p => p.slug === slug) @@ -45,10 +45,9 @@ export async function getStaticProps ({ params: { slug } }) { post.blockMap = await getPostBlocks(post.id, 'slug') - const posts = allPosts.filter(post => post?.type?.[0] === 'Post') - const index = posts.indexOf(post) - const prev = posts.slice(index - 1, index)[0] ?? posts.slice(-1)[0] - const next = posts.slice(index + 1, index + 2)[0] ?? posts[0] + const index = allPosts.indexOf(post) + const prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0] + const next = allPosts.slice(index + 1, index + 2)[0] ?? allPosts[0] const recommendPosts = getRecommendPost(post, allPosts) @@ -61,29 +60,33 @@ export async function getStaticProps ({ params: { slug } }) { recommendPosts, categories, postCount, - latestPosts + latestPosts, + customNav }, revalidate: 1 } } /** - * + * 获取文章的关联推荐文章列表,目前根据标签关联性筛选 * @param post * @param {*} allPosts * @param {*} count * @returns */ function getRecommendPost (post, allPosts, count = 5) { - let filteredPosts = Object.create(allPosts) - // 筛选同标签 + let filteredPosts = [] + for (const i in allPosts) { + const p = allPosts[i] + filteredPosts.push(Object.assign(p)) + } + if (post.tags && post.tags.length) { const currentTag = post.tags[0] filteredPosts = filteredPosts.filter( - p => p && p.tags && p.tags.includes(currentTag) && p.slug !== post.slug && p.type === 'post' + p => p && p.slug !== post.slug && p.tags && p.tags?.includes(currentTag) && p.type === ['Post'] ) } - shuffleSort(filteredPosts) // 筛选前5个 if (filteredPosts.length > count) { @@ -92,21 +95,4 @@ function getRecommendPost (post, allPosts, count = 5) { return filteredPosts } -/** - * 洗牌乱序:从数组的最后位置开始,从前面随机一个位置,对两个数进行交换,直到循环完毕 - * @param arr - * @returns {*} - */ -function shuffleSort (arr) { - let i = arr.length - 1 - while (i > 0) { - const rIndex = Math.floor(Math.random() * i) - const temp = arr[rIndex] - arr[rIndex] = arr[i] - arr[i] = temp - i-- - } - return arr -} - export default Slug diff --git a/pages/index.js b/pages/index.js index c499cd6f..be549212 100644 --- a/pages/index.js +++ b/pages/index.js @@ -9,7 +9,7 @@ const Index = (props) => { export async function getStaticProps () { const from = 'index' - const { allPosts, latestPosts, categories, tags, postCount } = await getGlobalNotionData({ from }) + const { allPosts, latestPosts, categories, tags, postCount, customNav } = await getGlobalNotionData({ from, pageType: ['Post'] }) const meta = { title: `${BLOG.TITLE}`, description: BLOG.DESCRIPTION, @@ -45,7 +45,8 @@ export async function getStaticProps () { postCount, tags, categories, - meta + meta, + customNav }, revalidate: 1 } diff --git a/pages/search.js b/pages/search.js index 79854860..5f765482 100644 --- a/pages/search.js +++ b/pages/search.js @@ -8,7 +8,7 @@ export async function getStaticProps () { tags, postCount, latestPosts - } = await getGlobalNotionData({ from: 'search-props' }) + } = await getGlobalNotionData({ from: 'search-props', pageType: ['Post'] }) return { props: { posts: allPosts, diff --git a/pages/tag/[tag].js b/pages/tag/[tag].js index 2c72b75f..01cf5220 100644 --- a/pages/tag/[tag].js +++ b/pages/tag/[tag].js @@ -50,10 +50,7 @@ function getTagNames (tags) { export async function getStaticPaths () { const from = 'tag-static-path' - const { tags } = await getGlobalNotionData({ - from, - tagsCount: 0 - }) + const { tags } = await getGlobalNotionData({ from, tagsCount: 0 }) const tagNames = getTagNames(tags) return { diff --git a/pages/tag/index.js b/pages/tag/index.js index 806cd993..eda44e7d 100644 --- a/pages/tag/index.js +++ b/pages/tag/index.js @@ -8,16 +8,7 @@ const TagIndex = (props) => { export async function getStaticProps () { const from = 'tag-index-props' - const { - categories, - tags, - postCount, - latestPosts - } = await getGlobalNotionData({ - from, - includePage: false, - tagsCount: 0 - }) + const { categories, tags, postCount, latestPosts } = await getGlobalNotionData({ from, tagsCount: 0 }) return { props: { diff --git a/themes/Empty/LayoutPage.js b/themes/Empty/LayoutPage.js index d4355d46..f25ee48f 100644 --- a/themes/Empty/LayoutPage.js +++ b/themes/Empty/LayoutPage.js @@ -1,4 +1,4 @@ -import LayoutBase from '../Hexo/LayoutBase' +import LayoutBase from '../Empty/LayoutBase' export const LayoutPage = (props) => { const { page } = props diff --git a/themes/Fukasawa/LayoutBase.js b/themes/Fukasawa/LayoutBase.js index 1d3f3a57..39603acb 100644 --- a/themes/Fukasawa/LayoutBase.js +++ b/themes/Fukasawa/LayoutBase.js @@ -20,17 +20,13 @@ const LayoutBase = (props) => { const { children, headerSlot, - tags, - meta, - currentCategory, - currentTag, - categories + meta } = props return (<>
- +
{headerSlot}
diff --git a/themes/Fukasawa/LayoutCategoryIndex.js b/themes/Fukasawa/LayoutCategoryIndex.js index 0def1581..0941d901 100644 --- a/themes/Fukasawa/LayoutCategoryIndex.js +++ b/themes/Fukasawa/LayoutCategoryIndex.js @@ -1,7 +1,5 @@ import BLOG from '@/blog.config' import { useGlobal } from '@/lib/global' -import { faFolder, faTh } from '@fortawesome/free-solid-svg-icons' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import Link from 'next/link' import LayoutBase from './LayoutBase' @@ -16,14 +14,14 @@ export const LayoutCategoryIndex = (props) => { return
- {locale.COMMON.CATEGORY}: + {locale.COMMON.CATEGORY}:
{Object.keys(categories).map(category => { return
- {category}({categories[category]}) + {category}({categories[category]})
})} diff --git a/themes/Fukasawa/LayoutSlug.js b/themes/Fukasawa/LayoutSlug.js index afa8f278..6834da3e 100644 --- a/themes/Fukasawa/LayoutSlug.js +++ b/themes/Fukasawa/LayoutSlug.js @@ -1,4 +1,5 @@ import BLOG from '@/blog.config' +import { getPageTableOfContents } from 'notion-utils' import 'prismjs' import 'prismjs/components/prism-bash' import 'prismjs/components/prism-javascript' @@ -17,6 +18,11 @@ export const LayoutSlug = (props) => { tags: post.tags } + if (post?.blockMap?.block) { + post.content = Object.keys(post.blockMap.block) + post.toc = getPageTableOfContents(post, post.blockMap) + } + return ( diff --git a/themes/Fukasawa/LayoutTagIndex.js b/themes/Fukasawa/LayoutTagIndex.js index 1d93708d..0642dbd9 100644 --- a/themes/Fukasawa/LayoutTagIndex.js +++ b/themes/Fukasawa/LayoutTagIndex.js @@ -1,7 +1,5 @@ import BLOG from '@/blog.config' import { useGlobal } from '@/lib/global' -import { faTag } from '@fortawesome/free-solid-svg-icons' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import TagItem from './components/TagItem' import LayoutBase from './LayoutBase' @@ -16,7 +14,7 @@ export const LayoutTagIndex = (props) => { return
-
{locale.COMMON.TAGS}:
+
{locale.COMMON.TAGS}:
{ tags.map(tag => { return
diff --git a/themes/Fukasawa/components/ArticleAround.js b/themes/Fukasawa/components/ArticleAround.js index 7f42e575..efb6c09b 100644 --- a/themes/Fukasawa/components/ArticleAround.js +++ b/themes/Fukasawa/components/ArticleAround.js @@ -1,6 +1,4 @@ import Link from 'next/link' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { faAngleDoubleLeft, faAngleDoubleRight } from '@fortawesome/free-solid-svg-icons' /** * 上一篇,下一篇文章 @@ -14,12 +12,12 @@ export default function ArticleAround ({ prev, next }) { return
- {prev.title} + {prev.title} {next.title} - +
diff --git a/themes/Fukasawa/components/ArticleDetail.js b/themes/Fukasawa/components/ArticleDetail.js index cdc46ff7..7974d413 100644 --- a/themes/Fukasawa/components/ArticleDetail.js +++ b/themes/Fukasawa/components/ArticleDetail.js @@ -1,8 +1,6 @@ import Comment from '@/components/Comment' import formatDate from '@/lib/formatDate' import { useGlobal } from '@/lib/global' -import { faEye, faFolderOpen } from '@fortawesome/free-solid-svg-icons' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import mediumZoom from 'medium-zoom' import Link from 'next/link' import 'prismjs' @@ -64,7 +62,7 @@ export default function ArticleDetail ({ post, recommendPosts, prev, next }) {
- + {post.category} @@ -83,7 +81,7 @@ export default function ArticleDetail ({ post, recommendPosts, prev, next }) { )}
- +   | diff --git a/themes/Fukasawa/components/AsideLeft.js b/themes/Fukasawa/components/AsideLeft.js index 79aaed1c..2b46e616 100644 --- a/themes/Fukasawa/components/AsideLeft.js +++ b/themes/Fukasawa/components/AsideLeft.js @@ -5,15 +5,18 @@ import GroupMenu from './GroupMenu' import GroupTag from './GroupTag' import SearchInput from './SearchInput' import SiteInfo from './SiteInfo' +import Catalog from './Catalog' + +function AsideLeft (props) { + const { tags, currentTag, categories, currentCategory, post } = props + console.log(post) -function AsideLeft ({ tags, currentTag, categories, currentCategory }) { return
-

- +
@@ -41,6 +44,10 @@ function AsideLeft ({ tags, currentTag, categories, currentCategory }) {
+
+ +
+
} diff --git a/themes/Fukasawa/components/Catalog.js b/themes/Fukasawa/components/Catalog.js new file mode 100644 index 00000000..c433e0d1 --- /dev/null +++ b/themes/Fukasawa/components/Catalog.js @@ -0,0 +1,81 @@ +import React from 'react' +import throttle from 'lodash.throttle' +import { uuidToId } from 'notion-utils' + +/** + * 目录导航组件 + * @param toc + * @returns {JSX.Element} + * @constructor + */ +const Catalog = ({ toc }) => { + // 无目录就直接返回空 + if (!toc || toc.length < 1) { + return <> + } + // 监听滚动事件 + React.useEffect(() => { + window.addEventListener('scroll', actionSectionScrollSpy) + actionSectionScrollSpy() + return () => { + window.removeEventListener('scroll', actionSectionScrollSpy) + } + }, []) + + // 同步选中目录事件 + const [activeSection, setActiveSection] = React.useState(null) + const throttleMs = 100 + const actionSectionScrollSpy = React.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 + } + setActiveSection(currentSectionId) + }, throttleMs)) + + return
+
目录
+ +
+} + +export default Catalog diff --git a/themes/Fukasawa/components/GroupCategory.js b/themes/Fukasawa/components/GroupCategory.js index 8e17fd5e..3dd437d8 100644 --- a/themes/Fukasawa/components/GroupCategory.js +++ b/themes/Fukasawa/components/GroupCategory.js @@ -1,5 +1,3 @@ -import { faFolder, faFolderOpen } from '@fortawesome/free-solid-svg-icons' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import Link from 'next/link' import React from 'react' @@ -17,7 +15,7 @@ function GroupCategory ({ currentCategory, categories }) { ? 'hover:text-white dark:hover:text-white bg-gray-600 text-white ' : 'dark:text-gray-400 text-gray-500 hover:text-white hover:bg-gray-500 dark:hover:text-white') + ' text-sm w-full items-center duration-300 px-2 cursor-pointer py-1 font-light'}> - {category}({categories[category]}) + {category}({categories[category]}) })} diff --git a/themes/Fukasawa/components/GroupMenu.js b/themes/Fukasawa/components/GroupMenu.js index 4b97583d..79fccdef 100644 --- a/themes/Fukasawa/components/GroupMenu.js +++ b/themes/Fukasawa/components/GroupMenu.js @@ -4,22 +4,26 @@ import { useRouter } from 'next/router' import { useGlobal } from '@/lib/global' import CONFIG_FUKA from '../config_fuka' -function GroupMenu () { +function GroupMenu ({ customNav }) { const { locale } = useGlobal() const router = useRouter() - const links = [ - { id: 0, name: locale.NAV.INDEX, to: '/' || '/', show: true }, - { id: 1, name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_FUKA.MENU_CATEGORY }, - { id: 2, name: locale.COMMON.TAGS, to: '/tag', show: CONFIG_FUKA.MENU_TAG }, - { id: 3, name: locale.NAV.ARCHIVE, to: '/archive', show: CONFIG_FUKA.MENU_ARCHIVE }, - { id: 4, name: locale.NAV.ABOUT, to: '/about', show: CONFIG_FUKA.MENU_ABOUT } + let links = [ + { name: locale.NAV.INDEX, to: '/' || '/', show: true }, + { name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_FUKA.MENU_CATEGORY }, + { name: locale.COMMON.TAGS, to: '/tag', show: CONFIG_FUKA.MENU_TAG }, + { name: locale.NAV.ARCHIVE, to: '/archive', show: CONFIG_FUKA.MENU_ARCHIVE } ] + + if (customNav) { + links = links.concat(customNav) + } + return