mirror of
https://github.com/YouHaveTrouble/youhavetrouble.github.io.git
synced 2026-08-28 00:56:42 +00:00
use collections and provide rss feed for the blog
This commit is contained in:
@@ -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,
|
||||
})),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user