From 5d9516104b6d5783b55d603d4a8a6f9fc709244d Mon Sep 17 00:00:00 2001 From: Yuhei Yasuda Date: Wed, 5 Jun 2024 20:12:51 +0900 Subject: [PATCH] include full content to rss feed --- src/pages/feed.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/pages/feed.ts b/src/pages/feed.ts index 62261ec..e62110e 100644 --- a/src/pages/feed.ts +++ b/src/pages/feed.ts @@ -1,6 +1,9 @@ import rss from '@astrojs/rss'; import type { APIContext } from 'astro'; +import { experimental_AstroContainer } from 'astro/container'; +import astroJSXRenderer from 'astro/jsx/renderer.js'; import { getCollection } from 'astro:content'; +import sanitizeHtml from 'sanitize-html'; import invariant from 'tiny-invariant'; import { siteDescription, siteTitle } from '../consts'; import { getBlogDescription } from '../lib/get-blog-description'; @@ -9,16 +12,24 @@ export async function GET(context: APIContext) { invariant(context.site); const entries = await getCollection('blog'); + const container = await experimental_AstroContainer.create({ + renderers: [astroJSXRenderer], + }); const items = await Promise.all( entries .toSorted((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()) .map(async (entry) => { const description = await getBlogDescription(entry); + const { Content } = await entry.render(); + const content = await container.renderToString(Content); return { link: `/${entry.slug}`, title: entry.data.title, pubDate: entry.data.pubDate, description, + content: sanitizeHtml(content, { + allowedTags: [...sanitizeHtml.defaults.allowedTags, 'img'], + }), }; }), );