From 6d488d83076a9179d40f298bf32d7d4491e1a44e Mon Sep 17 00:00:00 2001 From: Ruidy Date: Tue, 31 Dec 2024 13:59:35 +0100 Subject: [PATCH] feat: use dynamic routes with props --- src/pages/posts/post-1.md | 4 +--- src/pages/tags/[tag].astro | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/pages/tags/[tag].astro diff --git a/src/pages/posts/post-1.md b/src/pages/posts/post-1.md index e980348..6d0250e 100644 --- a/src/pages/posts/post-1.md +++ b/src/pages/posts/post-1.md @@ -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 diff --git a/src/pages/tags/[tag].astro b/src/pages/tags/[tag].astro new file mode 100644 index 0000000..9df9821 --- /dev/null +++ b/src/pages/tags/[tag].astro @@ -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)) +--- + + +

Posts tagged with {tag}

+ +