
import RSS from "rss";
import { getSortedPostsData } from "@/lib/posts";

export async function GET() {
  const feed = new RSS({
    title: "Gabriel Kaszewski's Blog",
    description: "A personal blog by Gabriel Kaszewski about technology, programming, and game development.",
    site_url: "https://blog.gabrielkaszewski.dev",
    feed_url: "https://blog.gabrielkaszewski.dev/feed.xml",
    language: "en",
    pubDate: new Date(),
    copyright: `© ${new Date().getFullYear()} Gabriel Kaszewski`,
  });

  const posts = getSortedPostsData();

  posts.forEach((post) => {
    feed.item({
      title: post.title,
      description: post.description,
      url: `https://blog.gabrielkaszewski.dev/posts/${post.id}`,
      guid: post.id,
      date: post.date,
    });
  });

  const xml = feed.xml({ indent: true });

  return new Response(xml, {
    headers: {
      "Content-Type": "application/xml; charset=utf-8",
    },
  });
}