I am trying for hours now to generate "categories" pages. I have one category per project(post) (string)
i think i am very close since the output of console.log(projects) shows only data from projects for the category, yet i get an error.
Cannot read properties of undefined (reading 'title')
Can someone nudge me in the right direction? Am I overthinking something? can this be done with the getCollection definition already maybe?
export async function getStaticPaths(){
const allProjects = await getCollection('projects');
const cats: string [] = [];
allProjects.forEach((proj) => {
const cat = proj.data.category.toLowerCase();
cats.push(cat);
})
return Array.from(new Set(cats)).map((cat) => {
return {
params: { cat },
props: {
cat,
projects: allProjects.filter((proj) => proj.data.category.includes(cat)),
},
};
});
}
type Props = CollectionEntry<'projects'>;
// const { cat } = Astro.params;
const projects = Astro.props;
console.log(projects);
const p = projects.data;
const titles = projects.data.title;