-
I created my SSG by following the docs with typescript. and I added tags in the blog posts(ex: tags: ["tech", "music"]). I want simply to implement a category page in my blog. How can I fetch posts by category or single tag? what i want is: localhost:port/tags/tech file tree: /pages/tags/[tag].tsx getStaticPaths:
getStaticProps:
getSortedPostData:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
In // pages/tags/[tag].tsx
export const getStaticPaths = async () => {
const tags = await getAllTags()
const paths = tags.map(({ tag }) => ({
params: {
tag
},
}));
return { paths, fallback: false };
}; In |
Beta Was this translation helpful? Give feedback.
-
Thanks, it worked. My problem was, I thought i could filter posts by an array. after I convert my multiple arrays of tags into a single array it worked. So, filtering with multiple strings from multiple arrays is not possible with my tags are like this: [ |
Beta Was this translation helpful? Give feedback.
In
getStaticPaths
,params.tags
shouldn't be an array. Try this.In
getStaticProps
, I don't thinkincludes
will work when you're comparing two arrays of tags. Instead, you probably want something likearray2.filter(e => !array1.includes(e))
.