diff --git a/src/lib/tags.ts b/src/lib/tags.ts index 4c9815d..eb67185 100644 --- a/src/lib/tags.ts +++ b/src/lib/tags.ts @@ -7,26 +7,25 @@ export type TagContent = { export function listTags(limit?: number): TagContent[] { const postContent = fetchPostContent(); - console.log('Received tags: '); - console.log(postContent.map((content) => content.tags)); - const allTags = - postContent && Array.isArray(postContent) && postContent.map - ? Array.from( - new Set( - postContent - .map((content) => content.tags) - .flat() - .filter((t) => t) - .map((t) => t.toLowerCase()), - ), - ) - : []; - const tags = allTags.map((tag) => ({ + if (!postContent || !Array.isArray(postContent)) { + return []; + } + + const tagSet = new Set( + // flatMap() polyfill + [].concat( + ...postContent.map((content) => + content.tags.filter((t) => t).map((t) => t.toLowerCase()), + ), + ), + ); + const tags = Array.from(tagSet).map((tag) => ({ name: tag, slug: tag, })); - if (!limit) { - return tags; + + if (limit) { + return tags.slice(0, limit); } - return tags.slice(0, limit); + return tags; } diff --git a/src/pages/posts/tags/[[...slug]].tsx b/src/pages/posts/tags/[[...slug]].tsx index e79e550..5e7b95f 100644 --- a/src/pages/posts/tags/[[...slug]].tsx +++ b/src/pages/posts/tags/[[...slug]].tsx @@ -67,13 +67,6 @@ export const getStaticProps: GetStaticProps = async ({ params }) => { }; export const getStaticPaths: GetStaticPaths = async () => { - const tags = listTags(); - if (!tags || !Array.isArray(tags) || !tags.flatMap) { - return { - paths: [], - fallback: false, - }; - } const paths = listTags().flatMap((tag) => { const pages = Math.ceil(countPosts(tag.slug) / config.posts_per_page); return Array.from(Array(pages).keys()).map((page) =>