import { urlsetXml, type Entry } from '@/lib/sitemap'; import { geographySlugsForSitemap } from '@/lib/queries/geography'; import { SITE_URL } from '@/lib/site'; import { toDate } from '@/lib/format'; export const dynamic = 'force-dynamic'; /** * Sitemap chunk for geography routes: /countries, /compare and one /country/ per geography that has * epidemiology observations. Static segment, so it takes precedence over /sitemap/[id] without touching it. */ export async function GET() { const now = new Date(); const geos = await geographySlugsForSitemap(); const entries: Entry[] = [ { url: `${SITE_URL}/countries`, lastModified: geos.map((g) => toDate(g.updated_at)).filter((d): d is Date => !!d).sort((a, b) => b.getTime() - a.getTime())[0] ?? now, changeFrequency: 'weekly', priority: 0.7 }, { url: `${SITE_URL}/compare`, lastModified: now, changeFrequency: 'weekly', priority: 0.5 }, ...geos.map((g) => ({ url: `${SITE_URL}/country/${g.slug}`, lastModified: toDate(g.updated_at) ?? now, changeFrequency: 'weekly' as const, priority: 0.7 })), ]; return new Response(urlsetXml(entries), { headers: { 'Content-Type': 'application/xml; charset=utf-8', 'Cache-Control': 'public, max-age=3600' } }); }