chore: fix rss feeds 67459f4b
Steve Simkins · 2026-05-29 21:28 2 file(s) · +28 −52
src/pages/feed.xml.ts +14 −26
1 1
import rss from "@astrojs/rss";
2 -
import { getCollection, render } from "astro:content";
3 -
import { experimental_AstroContainer as AstroContainer } from "astro/container";
4 -
import { loadRenderers } from "astro:container";
5 -
import { getContainerRenderer as getMDXRenderer } from "@astrojs/mdx";
2 +
import { getCollection } from "astro:content";
3 +
import MarkdownIt from "markdown-it";
6 4
import sanitizeHtml from "sanitize-html";
7 5
import siteMeta from "@/site-config";
6 +
7 +
const parser = new MarkdownIt({ html: true, linkify: true });
8 8
9 9
export async function GET() {
10 10
	const posts = await getCollection("post");
11 11
	const visiblePosts = posts.filter((post) => !post.data.hidden);
12 12
13 -
	const renderers = await loadRenderers([getMDXRenderer()]);
14 -
	const container = await AstroContainer.create({ renderers });
15 -
16 -
	const items = await Promise.all(
17 -
		visiblePosts.map(async (post) => {
18 -
			const { Content } = await render(post);
19 -
			const content = await container.renderToString(Content);
20 -
21 -
			return {
22 -
				title: post.data.title,
23 -
				description: post.data.description,
24 -
				pubDate: post.data.publishDate,
25 -
				link: `/posts/${post.id}`,
26 -
				content: sanitizeHtml(content, {
27 -
					allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
28 -
				}),
29 -
			};
30 -
		}),
31 -
	);
32 -
33 13
	return rss({
34 14
		title: siteMeta.title,
35 15
		description: siteMeta.description,
36 -
		site: process.env.SITE_URL || "https://stevedylan.dev",
37 -
		items: items,
16 +
		site: "https://stevedylan.dev",
17 +
		items: visiblePosts.map((post) => ({
18 +
			title: post.data.title,
19 +
			description: post.data.description,
20 +
			pubDate: post.data.publishDate,
21 +
			link: `/posts/${post.id}`,
22 +
			content: sanitizeHtml(parser.render(post.body ?? ""), {
23 +
				allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
24 +
			}),
25 +
		})),
38 26
	});
39 27
}
src/pages/rss.xml.ts +14 −26
1 1
import rss from "@astrojs/rss";
2 -
import { getCollection, render } from "astro:content";
3 -
import { experimental_AstroContainer as AstroContainer } from "astro/container";
4 -
import { loadRenderers } from "astro:container";
5 -
import { getContainerRenderer as getMDXRenderer } from "@astrojs/mdx";
2 +
import { getCollection } from "astro:content";
3 +
import MarkdownIt from "markdown-it";
6 4
import sanitizeHtml from "sanitize-html";
7 5
import siteMeta from "@/site-config";
6 +
7 +
const parser = new MarkdownIt({ html: true, linkify: true });
8 8
9 9
export async function GET() {
10 10
	const posts = await getCollection("post");
11 11
	const visiblePosts = posts.filter((post) => !post.data.hidden);
12 12
13 -
	const renderers = await loadRenderers([getMDXRenderer()]);
14 -
	const container = await AstroContainer.create({ renderers });
15 -
16 -
	const items = await Promise.all(
17 -
		visiblePosts.map(async (post) => {
18 -
			const { Content } = await render(post);
19 -
			const content = await container.renderToString(Content);
20 -
21 -
			return {
22 -
				title: post.data.title,
23 -
				description: post.data.description,
24 -
				pubDate: post.data.publishDate,
25 -
				link: `/posts/${post.id}`,
26 -
				content: sanitizeHtml(content, {
27 -
					allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
28 -
				}),
29 -
			};
30 -
		}),
31 -
	);
32 -
33 13
	return rss({
34 14
		title: siteMeta.title,
35 15
		description: siteMeta.description,
36 -
		site: process.env.SITE_URL || "https://stevedylan.dev",
37 -
		items: items,
16 +
		site: "https://stevedylan.dev",
17 +
		items: visiblePosts.map((post) => ({
18 +
			title: post.data.title,
19 +
			description: post.data.description,
20 +
			pubDate: post.data.publishDate,
21 +
			link: `/posts/${post.id}`,
22 +
			content: sanitizeHtml(parser.render(post.body ?? ""), {
23 +
				allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
24 +
			}),
25 +
		})),
38 26
	});
39 27
}