I have followed the tutorial up to the point of Generating pages from existing tags. There's a final code sample that I have copied into my tutorial project that I'm following along.
---
import BaseLayout from "../../layouts/BaseLayout.astro";
import BlogPost from "../../components/BlogPost.astro";
export async function getStaticPaths() {
const allPosts = await Astro.glob("../posts/*.md");
const uniqueTags = [
...new Set(allPosts.map((post) => post.frontmatter.tags).flat()),
];
return uniqueTags.map((tag) => {
const filteredPosts = allPosts.filter((post) =>
post.frontmatter.tags.includes(tag)
);
return {
params: { tag },
props: { posts: filteredPosts },
};
});
}
const { tag } = Astro.params;
const { posts } = Astro.props;
---
<BaseLayout pageTitle={tag}>
<p>Posts tagged with {tag}</p>
<ul>
{
posts.map((post) => (
<BlogPost url={post.url} title={post.frontmatter.title} />
))
}
</ul>
</BaseLayout>
But I get the following error:
Cannot read properties of undefined (reading 'map')
I have made sure that every blog post includes at least one tag