troylusty.com/src/pages/feed.xml.ts
Troy 782bfc7c90
All checks were successful
Docker / build-and-push-image (push) Successful in 2m11s
feat: create separated rss feeds
2025-05-06 22:50:48 +01:00

29 lines
798 B
TypeScript

import rss from "@astrojs/rss";
import { SITE } from "@consts";
import { getCollection } from "astro:content";
export async function GET(context: { site: string }) {
const posts = (await getCollection("posts")).filter(
(post) => !post.data.draft,
);
const projects = (await getCollection("projects")).filter(
(project) => !project.data.draft,
);
const items = [...posts, ...projects].sort(
(a, b) => new Date(b.data.date).valueOf() - new Date(a.data.date).valueOf(),
);
return rss({
title: SITE.TITLE,
description: SITE.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}/`,
})),
});
}