mirror of
https://github.com/rjNemo/orbital-orbit
synced 2026-06-06 06:56:40 +00:00
refactor: dynamic tag lists
This commit is contained in:
parent
5c62e71a64
commit
f06ae6b055
1 changed files with 9 additions and 11 deletions
|
|
@ -6,28 +6,26 @@ export async function getStaticPaths() {
|
|||
const posts = Object.values(
|
||||
import.meta.glob("../posts/*.md", { eager: true }),
|
||||
);
|
||||
return [
|
||||
{ params: { tag: "astro" }, props: { posts } },
|
||||
{ params: { tag: "successes" }, props: { posts } },
|
||||
{ params: { tag: "community" }, props: { posts } },
|
||||
{ params: { tag: "blogging" }, props: { posts } },
|
||||
{ params: { tag: "setbacks" }, props: { posts } },
|
||||
{ params: { tag: "learning in public" }, props: { posts } },
|
||||
const tags = [
|
||||
...new Set(posts.flatMap((post: any) => post.frontmatter.tags)),
|
||||
];
|
||||
return tags.map((tag: any) => {
|
||||
const filteredPosts = posts.filter((post: any) =>
|
||||
post.frontmatter.tags?.includes(tag),
|
||||
);
|
||||
return { params: { tag }, props: { posts: filteredPosts } };
|
||||
});
|
||||
}
|
||||
|
||||
const { tag } = Astro.params;
|
||||
const { posts } = Astro.props;
|
||||
const filteredPosts = posts.filter((post: any) =>
|
||||
post.frontmatter.tags?.includes(tag),
|
||||
);
|
||||
---
|
||||
|
||||
<BaseLayout pageTitle={`Posts tagged with ${tag}`}>
|
||||
<p>Posts tagged with {tag}</p>
|
||||
<ul>
|
||||
{
|
||||
filteredPosts.map((post: any) => (
|
||||
posts.map((post: any) => (
|
||||
<BLogPost url={post.url} title={post.frontmatter.title} />
|
||||
))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue