From 54026de51b498d75a3cfacdd72fb23d7e7c306ed Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Thu, 16 Dec 2021 21:36:26 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E9=A2=84=E7=BC=96=E8=AF=91tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/tag/[tag].js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/pages/tag/[tag].js b/pages/tag/[tag].js index a12f4643..24a42ae3 100644 --- a/pages/tag/[tag].js +++ b/pages/tag/[tag].js @@ -46,15 +46,32 @@ export async function getStaticProps ({ params }) { } } +/** + * 获取所有的标签 + * @param {*}} allPosts + * @returns + */ +function getTagNames (allPosts) { + const tags = allPosts.map(p => p.tags).flat() + + const tagObj = {} + tags.forEach(tag => { + if (tag in tagObj) { + tagObj[tag]++ + } else { + tagObj[tag] = 1 + } + }) + return tagObj +} + export async function getStaticPaths () { - // const tags = [] const from = 'tag-static-path' - const notionPageData = await getNotionPageData({ from }) - const posts = await getAllPosts({ notionPageData, from }) - const tagOptions = notionPageData.tagOptions - const tags = await getAllTags({ posts, tagOptions, sliceCount: 0 }) + const posts = await getAllPosts({ from }) + const tagNames = getTagNames(posts) + return { - paths: tags.map(t => ({ params: { tag: t.name } })), + paths: Object.keys(tagNames).map(tag => ({ params: { tag } })), fallback: true } }