fixes
This commit is contained in:
parent
7e1796b82d
commit
2ff196ff76
3 changed files with 70 additions and 12 deletions
40
src/pages/notes/feed.xml.js
Normal file
40
src/pages/notes/feed.xml.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
import rss from '@astrojs/rss';
|
||||
import conf from "~/site.config";
|
||||
import { getCollection } from 'astro:content';
|
||||
|
||||
import sanitizeHtml from 'sanitize-html';
|
||||
import MarkdownIt from 'markdown-it';
|
||||
import { formattedDate } from '~/lib/date';
|
||||
|
||||
const parser = new MarkdownIt();
|
||||
|
||||
export async function GET(context) {
|
||||
const blog = await getCollection('notes');
|
||||
return rss({
|
||||
// `<title>` field in output xml
|
||||
title: conf.site.title,
|
||||
// `<description>` field in output xml
|
||||
description: conf.site.description,
|
||||
// Pull in your project "site" from the endpoint context
|
||||
// https://docs.astro.build/en/reference/api-reference/#site
|
||||
site: context.site,
|
||||
stylesheet: "/feed.xsl",
|
||||
// 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 || `A note from ${formattedDate(post.data.date)}`,
|
||||
pubDate: post.data.date,
|
||||
description: post.data.description,
|
||||
// Compute RSS link from post `id`
|
||||
// This example assumes all posts are rendered as `/blog/[id]` routes
|
||||
link: `/notes/${post.id}/`,
|
||||
trailingSlash: false,
|
||||
content: sanitizeHtml(parser.render(post.body), {
|
||||
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img'])
|
||||
}),
|
||||
...post.data,
|
||||
})),
|
||||
// (optional) inject custom xml
|
||||
customData: `<language>en-gb</language>`,
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue