import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';

export async function GET(context) {
  const posts = await getCollection('posts', ({ data }) => data.published === true);
  return rss({
    title: 'cyperpunk.de',
    description: 'RSS Feed - DerGrumpf',
    site: context.site,
    items: posts.map((post) => ({
      title: post.data.title,
      pubDate: post.data.date,
      link: `/posts/${post.id}`,
    })),
  });
}
