website-astro/src/pages/tags/[tag].astro

31 lines
683 B
Plaintext
Raw Normal View History

2022-12-02 11:21:18 +01:00
---
import BaseLayout from "../../layouts/BaseLayout.astro";
export async function getStaticPaths({}) {
2023-02-03 11:25:43 +01:00
const allPosts = await Astro.glob("../../content/**/*.mdx");
2022-12-02 11:21:18 +01:00
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>
2022-12-28 10:36:15 +01:00
{posts.map((post) => <li>{post.frontmatter.title}</li>)}
2022-12-02 11:21:18 +01:00
</ul>
</BaseLayout>