feat: add RSS feed endpoint with sorted posts and metadata

This commit is contained in:
Ken
2026-05-26 23:25:10 +00:00
parent 10804705bc
commit b836b68ceb
2 changed files with 118 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
import type { APIContext } from 'astro';
export async function GET(context: APIContext) {
const posts = await getCollection('posts');
const base = import.meta.env.BASE_URL;
const sortedPosts = posts.sort(
(a, b) => b.data.date.getTime() - a.data.date.getTime()
);
return rss({
title: 'Crash Test Dev',
description: 'Technical publishing by Ken Chau',
site: context.site!,
items: sortedPosts.map((post) => ({
title: post.data.title,
pubDate: post.data.date,
description: post.data.summary ?? '',
link: `${base}posts/${post.id}/`,
})),
});
}