From 0077087a5179c2ffdec07ee38f3ffbbb01853dde Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sat, 3 Feb 2024 14:08:16 -0500 Subject: Guestbook; No more hardcoded date --- src/pages/blog/index.astro | 1 - src/pages/blog/rss.xml.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/pages/blog/rss.xml.js (limited to 'src/pages/blog') diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index 74f543a..a6b6855 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -8,7 +8,6 @@ const allBlogPosts = (await getCollection('blog')).sort((a, b) => b.data.pubDate ---
- {allBlogPosts.map((post) => (

{post.data.title}

diff --git a/src/pages/blog/rss.xml.js b/src/pages/blog/rss.xml.js new file mode 100644 index 0000000..fe17f91 --- /dev/null +++ b/src/pages/blog/rss.xml.js @@ -0,0 +1,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({ + // `` 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>`, + })), + }); +} -- cgit v1.2.3