From ac78eef58b15f43932434c285c6a32ac83f4fa2d Mon Sep 17 00:00:00 2001 From: afterlifepro Date: Thu, 14 Aug 2025 21:33:13 +0100 Subject: [PATCH] Generate a better RSS feed and generate styles to go along with it. The files had to be moved out of /rss bc having an index was breaking things. The `.xml` extension had to be added to stop firefox downloading it (???) idk man this is a bit scuffed but noone uses RSS anyway so like who gives a fuck --- src/pages/rss.style.xml.ts | 108 +++++++++++++++++++++++++++++++++++++ src/pages/rss.xml.ts | 63 ++++++++++++++++++++++ src/pages/rss/index.ts | 39 -------------- src/pages/rss/style.ts | 0 4 files changed, 171 insertions(+), 39 deletions(-) create mode 100644 src/pages/rss.style.xml.ts create mode 100644 src/pages/rss.xml.ts delete mode 100644 src/pages/rss/index.ts delete mode 100644 src/pages/rss/style.ts diff --git a/src/pages/rss.style.xml.ts b/src/pages/rss.style.xml.ts new file mode 100644 index 0000000..9b44374 --- /dev/null +++ b/src/pages/rss.style.xml.ts @@ -0,0 +1,108 @@ +import BoxTlbr from "/assets/box-tlbr.png"; +import Hr from "/assets/hr.png"; +import Box2x1Mask from "/assets/box-2x1-mask.png"; + +export async function GET() { + return new Response( + ` + + + + + + + RSS | vielle.dev + + + + +
+

Blog Posts

+

If you want to use this page in your RSS reader, simply paste this page's URL in and it'll just work. To view the original RSS, view the page source. The styling of this page is made possible by XSLT

+ + + + + +
+ + + + + + + +

+
+ + +
+
+
+
+ + +
+
+ `, + { + headers: { + "Content-Type": "text/xml", + }, + }, + ); +} diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts new file mode 100644 index 0000000..61419b5 --- /dev/null +++ b/src/pages/rss.xml.ts @@ -0,0 +1,63 @@ +import { getCollection } from "astro:content"; +import { getRssString } from "@astrojs/rss"; +import type { APIRoute } from "astro"; +import { experimental_AstroContainer } from "astro/container"; + +import image from "/content/blog/assets/nested.png"; +image.format; + +const container = await experimental_AstroContainer.create(); + +const postBodies = import.meta.glob("../content/blog/**/*.md"); +console.log("postBodies", postBodies); + +export const GET: APIRoute = async ({ site }) => { + const posts = await getCollection("blog"); + + const rss = await getRssString({ + title: "vielle.dev", + description: "Posts from vielle.dev", + site: site?.toString() ?? "", + items: await Promise.all( + posts.map(async (post) => { + const res = { + title: post.data.title, + description: post.data.bio, + pubDate: post.data.pub, + link: `/blog/${post.id}/`, + customData: await import( + `../content/blog/assets/${post.data.banner.replace(".png", "")}.png` + ).then( + ({ default: img }: { default: ImageMetadata }) => + // custom image component for the xslt transform + `${img.src}`, + ), + }; + + if (post.filePath) { + const { default: Content } = (await postBodies[ + `../content/blog/${post.id}.md` + ]()) as any; + const content = await container.renderToString(Content); + + return { + ...res, + content: content, + }; + } else return res; + }), + ), + }); + + return new Response( + rss.replace( + '', + '', + ), + { + headers: { + "Content-Type": "application/xml", + }, + }, + ); +}; diff --git a/src/pages/rss/index.ts b/src/pages/rss/index.ts deleted file mode 100644 index 6405fac..0000000 --- a/src/pages/rss/index.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { getCollection } from "astro:content"; -import rss from "@astrojs/rss"; -import type { APIRoute } from "astro"; -import { experimental_AstroContainer } from "astro/container"; - -const container = await experimental_AstroContainer.create(); - -export const GET: APIRoute = async ({ site }) => { - const posts = await getCollection("blog"); - - return rss({ - title: "vielle.dev", - description: "Posts from vielle.dev", - site: site?.toString() ?? "", - items: await Promise.all( - posts.map(async (post) => { - const res = { - title: post.data.title, - description: post.data.bio, - pubDate: post.data.pub, - link: `/blog/${post.id}/`, - }; - - if (post.filePath) { - /* its ssg so dynamic imports are fine. - ../../ is bc it includes src/components - so we need to go to project root */ - const { default: Component } = await import( - /* @vite-ignore */ `../../../${post.filePath}` - ); - const content = await container.renderToString(Component); - - return { ...res, content: content }; - } else return res; - }), - ), - // stylesheet: ``, - }); -}; diff --git a/src/pages/rss/style.ts b/src/pages/rss/style.ts deleted file mode 100644 index e69de29..0000000 -- 2.51.2