michaelrausch-24/src/pages/rss.xml.ts
2024-10-16 00:10:58 +13:00

31 lines
803 B
TypeScript

import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
import { HOME } from "@consts";
type Context = {
site: string
}
export async function GET(context: Context) {
const blog = (await getCollection("blog"))
.filter(post => !post.data.draft);
const projects = (await getCollection("projects"))
.filter(project => !project.data.draft);
const items = [...blog, ...projects]
.sort((a, b) => new Date(b.data.date).valueOf() - new Date(a.data.date).valueOf());
return rss({
title: HOME.TITLE,
description: HOME.DESCRIPTION,
site: context.site,
items: items.map((item) => ({
title: item.data.title,
description: item.data.description,
pubDate: item.data.date,
link: `/${item.collection}/${item.slug}/`,
})),
});
}