From 26ffc44ee72522891b4fdacac15134dfcf9c4859 Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Mon, 12 Jan 2026 22:27:17 +0100 Subject: Rework how tags are working and make them native --- src/pages/micro/[...page].astro | 7 ++- src/pages/micro/tags/[tag]/[...page].astro | 71 ++++++++++++++++++++++++++++++ src/pages/micro/tags/index.astro | 36 +++++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/pages/micro/tags/[tag]/[...page].astro create mode 100644 src/pages/micro/tags/index.astro (limited to 'src/pages/micro') diff --git a/src/pages/micro/[...page].astro b/src/pages/micro/[...page].astro index edfecab..8e7e814 100644 --- a/src/pages/micro/[...page].astro +++ b/src/pages/micro/[...page].astro @@ -51,7 +51,12 @@ const paginationProps = {

- Micro + Micro + + Browse tags + + RSS feed diff --git a/src/pages/micro/tags/[tag]/[...page].astro b/src/pages/micro/tags/[tag]/[...page].astro new file mode 100644 index 0000000..3f78663 --- /dev/null +++ b/src/pages/micro/tags/[tag]/[...page].astro @@ -0,0 +1,71 @@ +--- +import { getCollection } from "astro:content"; +import type { GetStaticPaths, InferGetStaticPropsType } from "astro"; +import { Icon } from "astro-icon/components"; +import Note from "@/components/note/Note.astro"; +import Pagination from "@/components/Paginator.astro"; +import PageLayout from "@/layouts/Base.astro"; +import { getUniqueMicroTags, sortMicroEntries } from "@/utils/micro"; + +export const getStaticPaths = (async ({ paginate }) => { + const allMicroPosts = await getCollection("micro"); + const sortedPosts = sortMicroEntries(allMicroPosts); + const uniqueTags = getUniqueMicroTags(sortedPosts); + + return uniqueTags.flatMap((tag) => { + const postsWithTag = sortedPosts.filter((post) => post.data.tags?.includes(tag)); + return paginate(postsWithTag, { + pageSize: 10, + params: { tag }, + }); + }); +}) satisfies GetStaticPaths; + +type Props = InferGetStaticPropsType; + +const { page } = Astro.props as Props; +const { tag } = Astro.params; + +const meta = { + description: `View all micro posts with the tag - ${tag}`, + title: `Micro posts about ${tag}`, +}; + +const paginationProps = { + ...(page.url.prev && { + prevUrl: { + text: "← Previous Page", + url: page.url.prev, + }, + }), + ...(page.url.next && { + nextUrl: { + text: "Next Page →", + url: page.url.next, + }, + }), +}; +--- + + + +

Micro posts about {tag}

+
    + { + page.data.map((note) => ( +
  • + +
  • + )) + } +
+ +
diff --git a/src/pages/micro/tags/index.astro b/src/pages/micro/tags/index.astro new file mode 100644 index 0000000..8d39b8a --- /dev/null +++ b/src/pages/micro/tags/index.astro @@ -0,0 +1,36 @@ +--- +import { getCollection } from "astro:content"; +import PageLayout from "@/layouts/Base.astro"; +import { getUniqueMicroTagsWithCount } from "@/utils/micro"; + +const allMicroPosts = await getCollection("micro"); +const allTags = getUniqueMicroTagsWithCount(allMicroPosts); + +const meta = { + description: "A list of all the topics I've written about in my micro posts", + title: "Micro Tags", +}; +--- + + +

Micro Tags

+
    + { + allTags.map(([tag, val]) => ( +
  • + + #{tag} + + + - {val} Post{val > 1 && "s"} + +
  • + )) + } +
+
-- cgit v1.2.3