diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/pages/blog/tags/[tag].astro | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/pages/blog/tags/[tag].astro b/src/pages/blog/tags/[tag].astro new file mode 100644 index 0000000..8885cfa --- /dev/null +++ b/src/pages/blog/tags/[tag].astro @@ -0,0 +1,28 @@ +--- +import Page from '../../../layouts/Page.astro'; + +export async function getStaticPaths() { + const allPosts = await Astro.glob('../../../content/blog/*.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; +--- +<Page title={tag}> + {posts.map((post) => { + return ( + <div> + <a href={post.url}>{post.frontmatter.title}</a> + </div> + ) + })} +</Page> |
