| 1 | import rss from "@astrojs/rss"; |
| 2 | import { getCollection } from "astro:content"; |
| 3 | import MarkdownIt from "markdown-it"; |
| 4 | import sanitizeHtml from "sanitize-html"; |
| 5 | import siteMeta from "@/site-config"; |
| 6 | |
| 7 | const parser = new MarkdownIt({ html: true, linkify: true }); |
| 8 | |
| 9 | export async function GET() { |
| 10 | const posts = await getCollection("post"); |
| 11 | const visiblePosts = posts.filter((post) => !post.data.hidden); |
| 12 | |
| 13 | return rss({ |
| 14 | title: siteMeta.title, |
| 15 | description: siteMeta.description, |
| 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 | })), |
| 26 | }); |
| 27 | } |