diff --git a/components/CategoryList.js b/components/CategoryList.js index 94c59244..045487d8 100644 --- a/components/CategoryList.js +++ b/components/CategoryList.js @@ -12,8 +12,10 @@ const CategoryList = ({ currentCategory, categories }) => { return (
  • diff --git a/components/RewardButton.js b/components/RewardButton.js index 1b436dff..579b5613 100644 --- a/components/RewardButton.js +++ b/components/RewardButton.js @@ -24,8 +24,8 @@ const RewardButton = () => {
    - - +
    +
    ) diff --git a/pages/article/[slug].js b/pages/article/[slug].js index 5e2fa52f..8cf2cd15 100644 --- a/pages/article/[slug].js +++ b/pages/article/[slug].js @@ -25,11 +25,12 @@ import RecommendPosts from '@/components/RecommendPosts' import TocDrawer from '@/components/TocDrawer' import TocDrawerButton from '@/components/TocDrawerButton' import { useGlobal } from '@/lib/global' +import { getNotionPageData } from '@/lib/notion/getNotionData' const mapPageUrl = id => { return 'https://www.notion.so/' + id.replace(/-/g, '') } -const ArticleDetail = ({ post, blockMap, tags, prev, next, posts, categories }) => { +const ArticleDetail = ({ post, blockMap, tags, prev, next, allPosts, categories }) => { if (!post) { return } @@ -44,7 +45,7 @@ const ArticleDetail = ({ post, blockMap, tags, prev, next, posts, categories }) const url = BLOG.link + useRouter().asPath const { locale } = useGlobal() - return + return
    @@ -110,7 +111,7 @@ const ArticleDetail = ({ post, blockMap, tags, prev, next, posts, categories }) {/* 推荐文章 */} - + {/* 版权声明 */}
    t.slug === slug) + const from = 'slug-props' + const notionPageData = await getNotionPageData({ from }) + let allPosts = await getAllPosts({ notionPageData, from, includePage: true }) + const post = allPosts.find(p => p.slug === slug) + if (!post) { - return { - props: {}, - revalidate: 1 - } + return { props: {}, revalidate: 1 } } const blockMap = await getPostBlocks(post.id, 'slug') + post.toc = [] if (blockMap) { post.toc = getPageTableOfContents(post, blockMap) - } else { - post.toc = [] } - posts = posts.filter(post => post.type[0] === 'Post') - const tags = await getAllTags(posts) - const categories = await getAllCategories(posts) - // 获取推荐文章 - 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] + allPosts = allPosts.filter(post => post.type[0] === 'Post') + const tagOptions = notionPageData.tagOptions + const tags = await getAllTags({ allPosts, tagOptions }) + const categories = await getAllCategories(allPosts) + // 上一篇、下一篇文章关联 + 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, blockMap, tags, prev, next, posts, categories }, + props: { post, blockMap, tags, prev, next, allPosts, categories }, revalidate: 1 } } diff --git a/pages/category/index.js b/pages/category/index.js index ca4b25e0..d2e1c882 100644 --- a/pages/category/index.js +++ b/pages/category/index.js @@ -16,7 +16,7 @@ export default function Category ({ tags, allPosts, categories }) { type: 'website' } return -
    +
    {locale.COMMON.CATEGORY}:
    diff --git a/pages/tag/index.js b/pages/tag/index.js index 750b38d7..aa441790 100644 --- a/pages/tag/index.js +++ b/pages/tag/index.js @@ -14,18 +14,18 @@ export default function Tag ({ tags, allPosts, categories }) { type: 'website' } return -
    -
    -
    {locale.COMMON.TAGS}:
    -
    - { - tags.map(tag => { - return
    - }) - } +
    +
    +
    {locale.COMMON.TAGS}:
    +
    + { + tags.map(tag => { + return
    + }) + } +
    -
    }