website: add rss feed for microlog

This commit is contained in:
2026-04-27 09:10:36 +01:00
parent b53412d728
commit 769c764feb
+29
View File
@@ -0,0 +1,29 @@
import path from "node:path";
import rss from "@astrojs/rss";
import type { APIContext } from "astro";
import { getCollection } from "astro:content";
import { renderGemtextToHtml } from "../../renderGemtextToHtml";
export async function GET(context: APIContext) {
// `site` is guaranteed to exist because we define it in our Astro config
const site = context.site!;
const posts = await getCollection("microlog");
return rss({
title: "Joe Carstairs microlog",
description: "My private X feed I guess?",
customData: `
<image>/images/headshot.webp</image>
<language>en-GB</language>
`,
site: path.join(site.toString(), "microlog"),
trailingSlash: false,
items: posts.map((post) => ({
link: `/microlog/${post.id}`,
title: post.id,
content: renderGemtextToHtml(post.body ?? ""),
pubDate: new Date(post.id.replace(/\.[0-9]+$/g, "")),
author: "Joe Carstairs",
})),
});
}