diff options
| author | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2024-05-19 10:00:08 +0100 |
|---|---|---|
| committer | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2024-05-19 10:00:08 +0100 |
| commit | cbef290b5bcbbb15db20f3943f56bf4293e42e49 (patch) | |
| tree | 9ed6c8f5af1d62000ac54205ffca52d7d8afb6f4 /website/src/pages/blog/rss.xml.ts | |
| parent | 55261df6fc572256566bfbc5a1aa1e3b97ba03e9 (diff) | |
Better RSS: post content, better positioning, TypeScript
Diffstat (limited to 'website/src/pages/blog/rss.xml.ts')
| -rw-r--r-- | website/src/pages/blog/rss.xml.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/website/src/pages/blog/rss.xml.ts b/website/src/pages/blog/rss.xml.ts new file mode 100644 index 0000000..c9ef251 --- /dev/null +++ b/website/src/pages/blog/rss.xml.ts @@ -0,0 +1,34 @@ +import rss from '@astrojs/rss'; +import type { APIContext } from 'astro'; +import { getCollection } from 'astro:content'; +import MarkdownIt from 'markdown-it'; + +const mdParser = new MarkdownIt(); + +export async function GET(context: APIContext) { + // `site` is guaranteed to exist because we define it in our Astro config + const site = context.site!; + const posts = await getCollection('blog'); + + return rss({ + title: 'Joe Carstairs’ blog', + description: 'Short posts on random topics I find interesting', + customData: ` + <image>/images/headshot.jpg</image> + <language>en-GB</language> + `, + site, + trailingSlash: false, + items: posts.map((post) => ({ + link: post.slug, + title: post.data.title, + content: mdParser.render(post.body), + pubDate: new Date(`${post.data.pubDate.year}-${post.data.pubDate.month}-${post.data.pubDate.day}`), + description: post.data.description, + author: 'Joe Carstairs', + + // A page for displaying comments related to the item + /* commentsUrl: `${post.slug}/comments`, */ + })), + }) +} |
