summaryrefslogtreecommitdiff
path: root/src/pages/blog/keywords
diff options
context:
space:
mode:
authorJoão Augusto Costa Branco Marado Torres <torres.dev@disroot.org>2025-06-24 12:08:41 -0300
committerJoão Augusto Costa Branco Marado Torres <torres.dev@disroot.org>2025-06-24 12:50:43 -0300
commitf9a77c5c27aede4e5978eb55d9b7af781b680a1d (patch)
treed545e325ba1ae756fc2eac66fac1001b6753c40d /src/pages/blog/keywords
feat!: initial commit
Signed-off-by: João Augusto Costa Branco Marado Torres <torres.dev@disroot.org>
Diffstat (limited to 'src/pages/blog/keywords')
-rw-r--r--src/pages/blog/keywords/[...slug].astro40
-rw-r--r--src/pages/blog/keywords/index.astro21
2 files changed, 61 insertions, 0 deletions
diff --git a/src/pages/blog/keywords/[...slug].astro b/src/pages/blog/keywords/[...slug].astro
new file mode 100644
index 0000000..724e8b7
--- /dev/null
+++ b/src/pages/blog/keywords/[...slug].astro
@@ -0,0 +1,40 @@
+---
+import { type CollectionEntry, getCollection } from "astro:content";
+import Base from "@layouts/Base.astro";
+import BlogCard from "@components/BlogCard.astro";
+
+type Props = { posts: CollectionEntry<"blog">[] };
+
+export async function getStaticPaths() {
+ const posts = await getCollection("blog");
+ const keywords = [
+ ...new Set(
+ await getCollection("blog").then((x) =>
+ x.flatMap((x) => x.data.keywords)
+ ),
+ ).values(),
+ ];
+ return keywords.map((k) => ({
+ params: { slug: k },
+ props: {
+ posts: posts.filter((post) =>
+ post.data.keywords.some((i) => i.localeCompare(k) === 0)
+ ),
+ },
+ }));
+}
+
+const title = "Blog";
+const description = "Latest articles.";
+
+const posts = Astro.props.posts.sort((a, b) =>
+ new Date(b.data.dateCreated).valueOf() -
+ new Date(a.data.dateCreated).valueOf()
+);
+---
+
+<Base {title} {description}>
+ <main>
+ <h2>Blogue</h2> {posts.map((post) => <BlogCard {...post} />)}
+ </main>
+</Base>
diff --git a/src/pages/blog/keywords/index.astro b/src/pages/blog/keywords/index.astro
new file mode 100644
index 0000000..255fbf4
--- /dev/null
+++ b/src/pages/blog/keywords/index.astro
@@ -0,0 +1,21 @@
+---
+import { getCollection } from "astro:content";
+import Base from "@layouts/Base.astro";
+
+const title = "Keywords";
+const description = "Keywords";
+
+const blogs = await getCollection("blog");
+let keywords = [
+ ...new Set([
+ ...blogs.flatMap(({ data }) => [...(data.keywords ?? [])]),
+ ]),
+];
+---
+
+<Base {title} {description} {keywords}>
+ <h1>Keywords</h1>
+ <ul>
+ {keywords.map((k) => <li><a href={`/blog/keywords/${k}`}>{k}</a></li>)}
+ </ul>
+</Base>