Skip to content

Commit

Permalink
include full content to rss feed
Browse files Browse the repository at this point in the history
  • Loading branch information
yuheiy committed Jun 5, 2024
1 parent 3a4abe0 commit 5d95161
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/pages/feed.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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'],
}),
};
}),
);
Expand Down

0 comments on commit 5d95161

Please sign in to comment.