import { NextResponse } from 'next/server'; import { countAssets } from '@/lib/queries/assets'; export const dynamic = 'force-dynamic'; const SITE = process.env.NEXT_PUBLIC_SITE_URL ?? 'https://www.rareindex.io'; const PAGE = 20_000; /** Sitemap index: /sitemap/0.xml (static + categories + indices + sets) then paginated asset sitemaps. */ export async function GET() { let n = 0; try { n = await countAssets(); } catch { n = 0; } const pages = 1 + Math.max(1, Math.ceil(n / PAGE)); const now = new Date().toISOString(); const body = `\n\n${Array.from({ length: pages }, (_, i) => ` ${SITE}/sitemap/${i}.xml${now}`).join('\n')}\n\n`; return new NextResponse(body, { headers: { 'content-type': 'application/xml; charset=utf-8', 'cache-control': 'public, max-age=3600' } }); }