diff options
Diffstat (limited to 'src/pages')
| -rw-r--r-- | src/pages/rss.xml.ts | 23 | ||||
| -rw-r--r-- | src/pages/tags/[tag]/rss.xml.ts | 23 |
2 files changed, 32 insertions, 14 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" />`, }); }; diff --git a/src/pages/tags/[tag]/rss.xml.ts b/src/pages/tags/[tag]/rss.xml.ts index 3a61414..89e158c 100644 --- a/src/pages/tags/[tag]/rss.xml.ts +++ b/src/pages/tags/[tag]/rss.xml.ts @@ -1,7 +1,9 @@ import rss from "@astrojs/rss"; import type { APIContext } from "astro"; +import sanitizeHtml from "sanitize-html"; import { getAllPosts, getUniqueTags } from "@/data/post"; import { siteConfig } from "@/site.config"; +import { markdownToHtml } from "@/utils/markdown"; export async function getStaticPaths() { // Get all posts (including archived, now includes pleroma too) @@ -37,13 +39,20 @@ export const GET = async (context: APIContext) => { title: `${siteConfig.title} - ${tag}`, description: `Posts tagged with ${tag}`, site, - items: sortedPosts.map((post) => ({ - title: post.data.title, - description: post.data.description, - pubDate: post.data.publishDate, - link: `posts/${post.id}/`, - author: post.data.author, - })), + items: sortedPosts.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="${site}tags/${tag}/rss.xml" rel="self" type="application/rss+xml" xmlns:atom="http://www.w3.org/2005/Atom" />`, }); }; |
