From 5fab0381b308eb5a1c837ffdd5e0ddd757e769d3 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Wed, 24 Jan 2024 22:50:02 -0500 Subject: Starting to work on blog --- src/pages/blog/[...slug].astro | 22 ++++++++++++++++++++++ src/pages/blog/index.astro | 8 ++++++++ src/pages/rss.xml.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/pages/blog/[...slug].astro create mode 100644 src/pages/blog/index.astro create mode 100644 src/pages/rss.xml.js (limited to 'src/pages') diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro new file mode 100644 index 0000000..7db75bb --- /dev/null +++ b/src/pages/blog/[...slug].astro @@ -0,0 +1,22 @@ +--- +import Page from '../../layouts/BlogPost.astro'; +import { getEntry } from 'astro:content'; +const { slug } = Astro.params; + +if (slug === undefined) { + throw new Error('Slug is required'); +} + +const entry = await getEntry('blog', slug); + +if(entry === undefined) { + return Astro.redirect('/404'); +} + +const { Content } = await entry.render(); +--- + +
+ +
+
diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro new file mode 100644 index 0000000..556be15 --- /dev/null +++ b/src/pages/blog/index.astro @@ -0,0 +1,8 @@ +--- +import Page from "../../layouts/Page.astro"; +--- + +
+ +
+
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({ + // `` 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>`, + })), + }); +} -- cgit v1.2.3