summaryrefslogtreecommitdiff
path: root/src/pages/posts/feed.xml.ts
blob: 43b9b84db2bb272b08c99ad3aa0b77b695e0e9af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
import { marked } from 'marked';
import type { APIContext } from 'astro';

export async function GET(context: APIContext) {
  const posts = await getCollection('posts');
  posts.sort((a, b) => b.data.date.localeCompare(a.data.date));

  return rss({
    title: "Matthew Kosarek's Blog",
    description: 'Updates and thoughts from Matthew Kosarek',
    site: context.site ?? 'https://matthewkosarek.xyz',
    items: posts.map(post => ({
      title: post.data.title,
      pubDate: new Date(post.data.date),
      link: `/posts/${post.slug}/`,
      content: marked(post.body) as string,
    })),
  });
}