feat: add RSS feed endpoint with sorted posts and metadata
This commit is contained in:
@@ -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}/`,
|
||||
})),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user