blob: fe17f91fa17d8210e6191d1233bf0ad89eab5c87 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import rss from '@astrojs/rss';
import { getCollection } from "astro:content";
import sanitizeHtml from 'sanitize-html';
import MarkdownIt from 'markdown-it';
const parser = new MarkdownIt();
export async function GET(context) {
const blog = await getCollection('blog');
return rss({
// `<title>` field in output xml
title: 'Andrew Lee',
// `<description>` field in output xml
description: 'Andrew Lee\'s Personal Blog',
// Pull in your project "site" from the endpoint context
// https://docs.astro.build/en/reference/api-reference/#contextsite
site: context.site,
// Array of `<item>`s in output xml
// See "Generating items" section for examples using content collections and glob imports
items: blog.map((post) => ({
title: post.data.title,
pubDate: post.data.pubDate,
description: post.data.description,
// Compute RSS link from post `slug`
// This example assumes all posts are rendered as `/blog/[slug]` routes
link: `/blog/${post.slug}/`,
content: sanitizeHtml(parser.render(post.body)),
// (optional) inject custom xml
customData: `<language>en-us</language>`,
})),
});
}
|