diff --git a/lib/notion/getAllTags.js b/lib/notion/getAllTags.js index aa0a6d9b..96af611c 100644 --- a/lib/notion/getAllTags.js +++ b/lib/notion/getAllTags.js @@ -30,7 +30,7 @@ export async function getAllTags ({ allPosts, sliceCount = 12, tagOptions }) { return { name: tag, count: tagObj[tag], color } }) list.sort((a, b) => b.count - a.count) - if (sliceCount) { + if (sliceCount && sliceCount > 0) { return list.slice(0, 12) } else { return list diff --git a/pages/tag/index.js b/pages/tag/index.js index 849418b9..4b19f810 100644 --- a/pages/tag/index.js +++ b/pages/tag/index.js @@ -2,17 +2,20 @@ import { getAllCategories, getAllPosts, getAllTags } from '@/lib/notion' import BLOG from '@/blog.config' import BaseLayout from '@/layouts/BaseLayout' import TagItem from '@/components/TagItem' +import { getNotionPageData } from '@/lib/notion/getNotionData' +import { useGlobal } from '@/lib/global' -export default function Tag ({ tags, posts, categories }) { +export default function Tag ({ tags, allPosts, categories }) { const meta = { title: `${BLOG.title} | 标签`, description: BLOG.description, type: 'website' } - return + const { locale } = useGlobal() + return
-
所有标签:
+
{locale.COMMON.TAGS}:
{ tags.map(tag => { @@ -26,16 +29,16 @@ export default function Tag ({ tags, posts, categories }) { } export async function getStaticProps () { - let posts = await getAllPosts({ from: 'tag-props' }) - posts = posts.filter( - post => post.status[0] === 'Published' && post.type[0] === 'Post' - ) - const tags = await getAllTags(posts, 0) - const categories = await getAllCategories(posts) + const from = 'tag-index-props' + const notionPageData = await getNotionPageData({ from }) + const allPosts = await getAllPosts({ notionPageData, from }) + const categories = await getAllCategories(allPosts) + const tagOptions = notionPageData.tagOptions + const tags = await getAllTags({ allPosts, sliceCount: 0, tagOptions }) return { props: { tags, - posts, + allPosts, categories }, revalidate: 1