From 52411f6cb9efc10dd683096b34e5c279a11f7e0a Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Tue, 13 Jan 2026 15:31:19 +0100 Subject: Rework how tags are working and make them native --- src/pages/micro/[...page].astro | 10 +++-- src/pages/micro/rss.xml.ts | 6 ++- src/pages/micro/tags/[tag]/[...page].astro | 71 ------------------------------ src/pages/micro/tags/index.astro | 36 --------------- 4 files changed, 10 insertions(+), 113 deletions(-) delete mode 100644 src/pages/micro/tags/[tag]/[...page].astro delete 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 8e7e814..d11d9ce 100644 --- a/src/pages/micro/[...page].astro +++ b/src/pages/micro/[...page].astro @@ -9,8 +9,10 @@ import PageLayout from "@/layouts/Base.astro"; export const getStaticPaths = (async ({ paginate }) => { const MAX_MICRO_PER_PAGE = 10; - // Get only Pleroma posts - const allMicro = await getCollection("micro").catch(() => []); // Fallback to empty array if micro collection fails + // Get only Pleroma posts tagged with "micro" + const allMicro = await getCollection("micro", ({ data }) => data.tags?.includes("micro")).catch( + () => [], + ); // Fallback to empty array if micro collection fails // Sort all micro posts const allMicroPosts = allMicro.sort( @@ -52,11 +54,11 @@ const paginationProps = {

Micro - + Browse tags - + RSS feed diff --git a/src/pages/micro/rss.xml.ts b/src/pages/micro/rss.xml.ts index 37d7d39..9356341 100644 --- a/src/pages/micro/rss.xml.ts +++ b/src/pages/micro/rss.xml.ts @@ -4,8 +4,10 @@ import type { APIContext } from "astro"; import { siteConfig } from "@/site.config"; export const GET = async (context: APIContext) => { - // Get only Pleroma posts - const allMicro = await getCollection("micro").catch(() => []); // Fallback to empty array if micro collection fails + // Get only Pleroma posts tagged with "micro" + const allMicro = await getCollection("micro", ({ data }) => data.tags?.includes("micro")).catch( + () => [], + ); // Fallback to empty array if micro collection fails // Sort all micro posts const allMicroPosts = allMicro.sort( diff --git a/src/pages/micro/tags/[tag]/[...page].astro b/src/pages/micro/tags/[tag]/[...page].astro deleted file mode 100644 index 3f78663..0000000 --- a/src/pages/micro/tags/[tag]/[...page].astro +++ /dev/null @@ -1,71 +0,0 @@ ---- -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 deleted file mode 100644 index 8d39b8a..0000000 --- a/src/pages/micro/tags/index.astro +++ /dev/null @@ -1,36 +0,0 @@ ---- -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