import rss from '@astrojs/rss';
import { getPublishedPosts } from '../lib/posts';
import { site } from '../lib/siteConfig';
import { absoluteUrl } from '../lib/seo';

export function GET() {
  return rss({
    title: site.title,
    description: site.description,
    site: site.base_url,
    items: getPublishedPosts().map((post) => ({
      title: post.title,
      description: post.summary ?? '',
      link: absoluteUrl(post.url),
      pubDate: post.date ? new Date(post.date) : undefined,
      categories: post.tags
    }))
  });
}
