import type { APIRoute } from 'astro';

import { sitemapEntries } from '@/lib/seo';

export const GET: APIRoute = async () => {
    const urls = (await sitemapEntries())
        .map((url) => `  <url><loc>${url}</loc></url>`)
        .join('\n');

    const body = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urls}
</urlset>`;

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