devblog/src/pages/rss.xml.js

29 lines
920 B
JavaScript
Raw Normal View History

2024-12-25 02:14:10 -05:00
import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
2025-03-08 19:45:21 -05:00
import getSortedPosts from "@/utils/getSortedPosts";
2025-05-17 21:18:28 -04:00
import sanitizeHtml from "sanitize-html";
import MarkdownIt from "markdown-it";
2025-03-08 19:45:21 -05:00
import { SITE } from "@/config";
2024-12-25 02:14:10 -05:00
2025-05-17 21:18:28 -04:00
const parser = new MarkdownIt();
2024-12-25 02:14:10 -05:00
export async function GET() {
const posts = await getCollection("blog");
const sortedPosts = getSortedPosts(posts);
return rss({
title: SITE.title,
description: SITE.desc,
site: SITE.website,
2025-03-28 02:34:52 -04:00
items: sortedPosts.map(({ data, id }) => ({
2025-03-08 19:45:21 -05:00
link: `posts/${id}/`,
2025-05-17 21:18:28 -04:00
content: sanitizeHtml(parser.render(posts.body), {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
}),
2024-12-25 02:14:10 -05:00
title: data.title,
description: data.description,
pubDate: new Date(data.modDatetime ?? data.pubDatetime),
2025-05-17 21:18:28 -04:00
customData: `<summary>${posts.frontmatter.description}</summary>`,
2024-12-25 02:14:10 -05:00
})),
});
}