From 42662ae3db2a2f2366942ab7d68f9441e03b29bb Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Tue, 13 Jan 2026 19:06:55 +0100 Subject: Add full content render for rss feed --- src/pages/rss.xml.ts | 23 ++++++++++++++++------- src/pages/tags/[tag]/rss.xml.ts | 23 ++++++++++++++++------- 2 files changed, 32 insertions(+), 14 deletions(-) (limited to 'src/pages') 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: ``, }); }; 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: ``, }); }; -- cgit v1.2.3