+15
-4
src/pages/rss.xml.ts
+15
-4
src/pages/rss.xml.ts
···
1
1
import { getCollection } from "astro:content";
2
2
import rss from "@astrojs/rss";
3
3
import type { APIRoute } from "astro";
4
+
import { experimental_AstroContainer } from "astro/container";
5
+
6
+
const container = await experimental_AstroContainer.create();
4
7
5
8
export const GET: APIRoute = async ({ site }) => {
6
9
const posts = await getCollection("blog");
···
11
14
site: site?.toString() ?? "",
12
15
items: await Promise.all(
13
16
posts.map(async (post) => {
14
-
const content = "TODO";
15
-
16
-
return {
17
+
const res = {
17
18
title: post.data.title,
18
19
description: post.data.bio,
19
20
pubDate: post.data.pub,
20
21
link: `/blog/${post.id}/`,
21
-
content: content,
22
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;
23
34
}),
24
35
),
25
36
// stylesheet: ``,