mirror of
https://codeberg.org/HPCesia/AstralHalo.git
synced 2025-04-08 17:34:27 +08:00
27 lines
832 B
TypeScript
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']),
|
|
}),
|
|
})),
|
|
});
|
|
};
|