feat: use dynamic routes with props

This commit is contained in:
Ruidy 2024-12-31 13:59:35 +01:00
parent 461c059480
commit 6d488d8307
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
2 changed files with 28 additions and 3 deletions

View file

@ -7,9 +7,7 @@ author: Ruidy
image:
url: "https://docs.astro.build/assets/rose.webp"
alt: "The Astro logo on a dark background with a pink glow."
tags:
- astro
- blog
tags: ["astro", "blogging", "learning in public"]
---
Welcome to my _new blog_ about learning Astro! Here, I will share my learning journey

View file

@ -0,0 +1,27 @@
---
import BLogPost from "../../components/BLogPost.astro";
import BaseLayout from "../../layouts/BaseLayout.astro"
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 { 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 )=> <BLogPost url={post.url} title={post.frontmatter.title}/>)}
</ul>
</BaseLayout>