mirror of
https://github.com/maciejpedzich/maciejpedzi.ch.git
synced 2025-04-05 06:11:13 +02:00
27 lines
666 B
JavaScript
27 lines
666 B
JavaScript
import rss from '@astrojs/rss';
|
|
import { getCollection } from 'astro:content';
|
|
import { SITE_TITLE, SITE_DESCRIPTION } from '../consts';
|
|
|
|
export async function GET(context) {
|
|
const posts = (await getCollection('blog'))
|
|
.filter((p) => !p.data.draft)
|
|
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
|
|
|
|
const { body } = await rss({
|
|
title: SITE_TITLE,
|
|
description: SITE_DESCRIPTION,
|
|
site: context.site,
|
|
items: posts.map((post) => ({
|
|
...post.data,
|
|
link: `/blog/${post.slug}/`
|
|
}))
|
|
});
|
|
|
|
return new Response(body, {
|
|
status: 200,
|
|
headers: {
|
|
'Content-Type': 'application/rss+xml'
|
|
}
|
|
});
|
|
}
|