2024-04-22 23:42:47 +08:00
|
|
|
import rss from '@astrojs/rss';
|
|
|
|
import {siteConfig} from '@/config';
|
|
|
|
import sanitizeHtml from 'sanitize-html';
|
|
|
|
import MarkdownIt from 'markdown-it';
|
2024-07-20 23:47:40 +08:00
|
|
|
import {getSortedPosts} from "@utils/content-utils.ts";
|
2024-04-22 23:42:47 +08:00
|
|
|
const parser = new MarkdownIt();
|
|
|
|
|
|
|
|
export async function GET(context: any) {
|
2024-07-20 23:47:40 +08:00
|
|
|
const blog = await getSortedPosts();
|
2024-04-22 23:42:47 +08:00
|
|
|
return rss({
|
|
|
|
title: siteConfig.title,
|
|
|
|
description: siteConfig.subtitle || 'No description',
|
|
|
|
site: context.site,
|
|
|
|
items: blog.map((post) => ({
|
|
|
|
title: post.data.title,
|
|
|
|
pubDate: post.data.published,
|
|
|
|
description: post.data.description,
|
|
|
|
link: `/posts/${post.slug}/`,
|
|
|
|
content: sanitizeHtml(parser.render(post.body), {
|
|
|
|
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img'])
|
|
|
|
}),
|
|
|
|
})),
|
|
|
|
customData: `<language>${siteConfig.lang}</language>`,
|
|
|
|
});
|
|
|
|
}
|