use collections and provide rss feed for the blog

This commit is contained in:
2024-07-22 19:37:18 +02:00
parent 0bca511144
commit 3cc883d082
13 changed files with 1876 additions and 1486 deletions
+22
View File
@@ -0,0 +1,22 @@
import rss from '@astrojs/rss';
import sanitizeHtml from 'sanitize-html';
import { marked } from 'marked';
import {getCollection} from "astro:content";
export async function GET(context: { site: any; }) {
const posts = await getCollection('posts');
return rss({
title: 'YouHaveBlog',
description: 'Something that\'s supposed to be thoughts.',
site: context.site,
items: posts.map((post) => ({
link: `/blog/${post.slug}/`,
content: sanitizeHtml(marked.parse(post.body), {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img'])
}),
pubDate: new Date(post.data.publishDate),
...post.data,
})),
});
}