import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
import type { APIContext } from "astro";
import { site } from "@data/site";

export async function GET(context: APIContext) {
  const posts = await getCollection("insights", ({ data }) => !data.draft);

  return rss({
    title: `${site.name} Insights`,
    description:
      "Articles, market notes, case studies, and announcements from BlueCap Strategies.",
    site: context.site ?? "https://www.bluecapstrategies.com",
    items: posts.map((post) => ({
      title: post.data.title,
      description: post.data.description,
      pubDate: post.data.publishDate,
      link: `/insights/${post.slug}/`,
      categories: post.data.tags,
    })),
  });
}
