import rss from "@astrojs/rss";
import type { APIContext } from "astro";
import { getLinks } from "@/lib/collections";

export async function GET(context: APIContext) {
  const links = await getLinks();

  const items = links.map((link) => ({
    title: link.data.title,
    description: link.data.description ?? link.data.title,
    pubDate: link.data.publishDate,
    link: `/links/${link.id}/`,
  }));

  return rss({
    title: "Adrian Altner — Links",
    description: "Curated links worth sharing.",
    site: context.site ?? new URL("https://adrian-altner.com"),
    items,
    customData: "<language>en-us</language>",
  });
}
