diff options
| author | Dawid Rycerz <dawid@rycerz.xyz> | 2026-01-13 19:06:55 +0100 |
|---|---|---|
| committer | Dawid Rycerz <dawid@rycerz.xyz> | 2026-01-13 19:06:55 +0100 |
| commit | 42662ae3db2a2f2366942ab7d68f9441e03b29bb (patch) | |
| tree | cbeea04301500f180fc1c6973e3d7222469e5f45 /src/pages/rss.xml.ts | |
| parent | c4afcab46587ace0a9f3b22592f6d17c62ff9e0e (diff) | |
Add full content render for rss feed
Diffstat (limited to 'src/pages/rss.xml.ts')
| -rw-r--r-- | src/pages/rss.xml.ts | 23 |
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" />`, }); }; |
