#Generate category pages
4 messages · Page 1 of 1 (latest)
I'd check out this section in the tutorial. It's for generating tags, so similar to what you're after!
https://docs.astro.build/en/tutorial/5-astro-api/2/
Any specific questions, feel free to ask away. I went through this and found it worked well
That page does not use content collections.
here's my tag page (that uses content collections)
---
import { getCollection } from 'astro:content';
export async function getStaticPaths() {
const allPosts = await getCollection('blog').then((collection) => collection.reverse());
const tags: string[] = [];
allPosts.forEach((post) => {
post.data.tags.forEach((tag) => {
tags.push(tag.toLowerCase());
});
});
return Array.from(new Set(tags)).map((tag) => {
return {
params: { tag },
props: {
tag,
blogposts: allPosts.filter((post) => post.data.tags.map(tag => tag.toLowerCase()).includes(tag)),
},
};
});
}
const { tag, blogposts } = Astro.props;
---
This might give you some ideas