blob: db8cfff96db6c61997de7c1c17e0b2b0e00735eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
import type { APIRoute } from 'astro';
function sortPosts(a: { data: { publishDate: Date } }, b: { data: { publishDate: Date } }) {
return Number(b.data.publishDate) - Number(a.data.publishDate);
}
function formatDate(date: Date) {
date.setUTCHours(0);
return date;
}
export const GET: APIRoute = async (context) => {
const unsortedPosts = [...(await getCollection('blog'))];
const posts = unsortedPosts.sort((a, b) => sortPosts(a, b));
return rss({
title: 'Polyfrost Blog',
description: 'Recieve Polyfrost updates here',
site: context.site!.href,
items: posts.map(post => ({
...post.data,
title: post.data.title,
description: post.data.description,
pubDate: formatDate(post.data.publishDate),
link: `/blog/${post.slug}/`,
})),
});
};
|