import rss from "@astrojs/rss";
import type { APIContext } from "astro";
import { getPosts } from "../lib/blog";
import { site } from "../data/site";

export async function GET(context: APIContext) {
  const posts = await getPosts(); // drafts excluded in prod
  return rss({
    title: `${site.name} — Blog`,
    description:
      "Notes on platform engineering, edge Kubernetes, GPUs and homelab infrastructure.",
    site: context.site ?? site.url,
    items: posts.map((post) => ({
      title: post.data.title,
      pubDate: post.data.date,
      description: post.data.summary,
      categories: post.data.tags,
      link: `/blog/${post.id}/`,
    })),
  });
}
