AstralHalo/src/pages/rss.xml.ts
HPCesia 03a70c675e feat: remove stylesheet of RSS feed
A third-party stylesheet should not be a part of template.
2025-04-02 15:16:05 +08:00

27 lines
832 B
TypeScript

import { siteConfig } from '@/config';
import rss from '@astrojs/rss';
import { getSortedPosts } from '@utils/content-utils';
import type { APIRoute } from 'astro';
import MarkdownIt from 'markdown-it';
import sanitizeHtml from 'sanitize-html';
const parser = new MarkdownIt();
export const GET: APIRoute = async function (context) {
const posts = await getSortedPosts();
return rss({
title: siteConfig.title,
description: siteConfig.subtitle,
site: context.site || '',
items: posts.map((post) => ({
title: post.data.title,
pubDate: post.data.published,
description: post.data.description,
link: `/posts/${post.data.slug}`,
content: sanitizeHtml(parser.render(post.body || ''), {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),
}),
})),
});
};