From df911b6c19dc039c5e622000e0cffd86ab920811 Mon Sep 17 00:00:00 2001 From: afterlifepro Date: Thu, 14 Aug 2025 17:45:47 +0100 Subject: [PATCH] Render markdown using the container API This resolves images/links/etc just like it would when rendering to HTML in the /blog/* pages. Note that container is an experimental API and may not work forever but since its a prerendered page idc to much --- src/pages/rss.xml.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts index cbabb4b..b618c3e 100644 --- a/src/pages/rss.xml.ts +++ b/src/pages/rss.xml.ts @@ -1,6 +1,9 @@ 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"); @@ -11,15 +14,23 @@ export const GET: APIRoute = async ({ site }) => { site: site?.toString() ?? "", items: await Promise.all( posts.map(async (post) => { - const content = "TODO"; - - return { + const res = { title: post.data.title, description: post.data.bio, pubDate: post.data.pub, link: `/blog/${post.id}/`, - content: content, }; + + if (post.filePath) { + /* its ssg so dynamic imports are fine. + ../../ is bc it includes src/components + so we need to go to project root */ + /* @vite-ignore */ + const { default: Component } = await import(`../../${post.filePath}`); + const content = await container.renderToString(Component); + + return { ...res, content: content }; + } else return res; }), ), // stylesheet: ``, -- 2.51.2