From 633d83beb5a5f3caf3b042eb5096efcb9ba03dac Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 1 Dec 2021 12:47:17 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E6=89=80=E6=9C=89=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E9=A1=B5=E6=95=B0=E9=87=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getAllTags.js | 2 +- pages/tag/index.js | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) 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