aboutsummaryrefslogtreecommitdiff
path: root/src/pages/rss.xml.js
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@protonmail.com>2024-01-24 22:50:02 -0500
committerAndrew Lee <alee14498@protonmail.com>2024-01-24 23:17:14 -0500
commit5fab0381b308eb5a1c837ffdd5e0ddd757e769d3 (patch)
tree2a08add3e122f2d1fc91d30908e37a7df46ceaa8 /src/pages/rss.xml.js
parent2c37ad34e91893596547060e0ab6bd320ef31bde (diff)
downloadpersonal-website-5fab0381b308eb5a1c837ffdd5e0ddd757e769d3.tar.gz
personal-website-5fab0381b308eb5a1c837ffdd5e0ddd757e769d3.tar.bz2
personal-website-5fab0381b308eb5a1c837ffdd5e0ddd757e769d3.zip
Starting to work on blog
Diffstat (limited to 'src/pages/rss.xml.js')
-rw-r--r--src/pages/rss.xml.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js
new file mode 100644
index 0000000..df0645d
--- /dev/null
+++ b/src/pages/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({
+ // `<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.date,
+ 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>`,
+ })),
+ });
+}