aboutsummaryrefslogtreecommitdiff
path: root/apps/website/src/pages/rss.xml.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/website/src/pages/rss.xml.ts')
-rw-r--r--apps/website/src/pages/rss.xml.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/apps/website/src/pages/rss.xml.ts b/apps/website/src/pages/rss.xml.ts
new file mode 100644
index 0000000..db8cfff
--- /dev/null
+++ b/apps/website/src/pages/rss.xml.ts
@@ -0,0 +1,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}/`,
+ })),
+ });
+};