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

vielle.dev df911b6c af79c245

verified
Changed files
+15 -4
src
pages
+15 -4
src/pages/rss.xml.ts
··· 1 import { getCollection } from "astro:content"; 2 import rss from "@astrojs/rss"; 3 import type { APIRoute } from "astro"; 4 5 export const GET: APIRoute = async ({ site }) => { 6 const posts = await getCollection("blog"); ··· 11 site: site?.toString() ?? "", 12 items: await Promise.all( 13 posts.map(async (post) => { 14 - const content = "TODO"; 15 - 16 - return { 17 title: post.data.title, 18 description: post.data.bio, 19 pubDate: post.data.pub, 20 link: `/blog/${post.id}/`, 21 - content: content, 22 }; 23 }), 24 ), 25 // stylesheet: ``,
··· 1 import { getCollection } from "astro:content"; 2 import rss from "@astrojs/rss"; 3 import type { APIRoute } from "astro"; 4 + import { experimental_AstroContainer } from "astro/container"; 5 + 6 + const container = await experimental_AstroContainer.create(); 7 8 export const GET: APIRoute = async ({ site }) => { 9 const posts = await getCollection("blog"); ··· 14 site: site?.toString() ?? "", 15 items: await Promise.all( 16 posts.map(async (post) => { 17 + const res = { 18 title: post.data.title, 19 description: post.data.bio, 20 pubDate: post.data.pub, 21 link: `/blog/${post.id}/`, 22 }; 23 + 24 + if (post.filePath) { 25 + /* its ssg so dynamic imports are fine. 26 + ../../ is bc it includes src/components 27 + so we need to go to project root */ 28 + /* @vite-ignore */ 29 + const { default: Component } = await import(`../../${post.filePath}`); 30 + const content = await container.renderToString(Component); 31 + 32 + return { ...res, content: content }; 33 + } else return res; 34 }), 35 ), 36 // stylesheet: ``,