46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import rss from '@astrojs/rss';
|
|
import { getCollection } from 'astro:content';
|
|
import { site } from '../site.config';
|
|
|
|
export async function GET(context: { site?: URL }) {
|
|
const [stories, briefings, episodes] = await Promise.all([
|
|
getCollection('stories', ({ data }) => !data.draft),
|
|
getCollection('briefings', ({ data }) => !data.draft),
|
|
getCollection('episodes', ({ data }) => !data.draft),
|
|
]);
|
|
|
|
const items = [
|
|
...stories.map((entry) => ({
|
|
title: entry.data.title,
|
|
description: entry.data.description,
|
|
pubDate: entry.data.published,
|
|
link: `/stories/${entry.id}`,
|
|
editorialOrder: entry.data.editorialOrder,
|
|
})),
|
|
...briefings.map((entry) => ({
|
|
title: entry.data.title,
|
|
description: entry.data.description,
|
|
pubDate: entry.data.published,
|
|
link: `/briefing/${entry.id}`,
|
|
editorialOrder: 1_000,
|
|
})),
|
|
...episodes.map((entry) => ({
|
|
title: entry.data.title,
|
|
description: entry.data.description,
|
|
pubDate: entry.data.published,
|
|
link: `/podcast/${entry.id}`,
|
|
editorialOrder: 1_000,
|
|
})),
|
|
]
|
|
.sort((a, b) => b.pubDate.valueOf() - a.pubDate.valueOf() || a.editorialOrder - b.editorialOrder)
|
|
.map(({ editorialOrder: _editorialOrder, ...item }) => item);
|
|
|
|
return rss({
|
|
title: `${site.title} ${site.qualifier}`,
|
|
description: site.description,
|
|
site: context.site ?? new URL('https://example.com'),
|
|
items,
|
|
customData: '<language>en-gb</language>',
|
|
});
|
|
}
|