summaryrefslogtreecommitdiff
path: root/src/pages/rss.xml.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/rss.xml.ts')
-rw-r--r--src/pages/rss.xml.ts23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts
index d428cc9..61adea7 100644
--- a/src/pages/rss.xml.ts
+++ b/src/pages/rss.xml.ts
@@ -1,7 +1,9 @@
import rss from "@astrojs/rss";
import type { APIContext } from "astro";
+import sanitizeHtml from "sanitize-html";
import { getAllPosts } from "@/data/post";
import { siteConfig } from "@/site.config";
+import { markdownToHtml } from "@/utils/markdown";
export const GET = async (context: APIContext) => {
const posts = await getAllPosts();
@@ -10,13 +12,20 @@ export const GET = async (context: APIContext) => {
title: siteConfig.title,
description: siteConfig.description,
site: context.site || import.meta.env.SITE,
- items: posts.map((post) => ({
- title: post.data.title,
- description: post.data.description,
- pubDate: post.data.publishDate,
- link: `posts/${post.id}/`,
- author: post.data.author,
- })),
+ items: posts.map((post) => {
+ const htmlContent = post.rendered?.html || markdownToHtml(post.body || "");
+
+ return {
+ title: post.data.title,
+ description: post.data.description,
+ pubDate: post.data.publishDate,
+ link: `posts/${post.id}/`,
+ author: post.data.author,
+ content: sanitizeHtml(htmlContent, {
+ allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
+ }),
+ };
+ }),
customData: `<atom:link href="${context.site}rss.xml" rel="self" type="application/rss+xml" xmlns:atom="http://www.w3.org/2005/Atom" />`,
});
};