const API_URL = process.env.NEXT_PUBLIC_API_URL; const MAIN_DOMAIN = 'https://nobat724.com'; const PER_SITEMAP = 1000; export async function generateSitemaps() { if (!API_URL) return [{ id: 0 }]; try { const res = await fetch(`${API_URL}/api/v1/clinics?page=1&limit=1`, { next: { revalidate: 86400 }, }); if (!res.ok) return [{ id: 0 }]; const json = await res.json(); const total = json?.meta?.totalRecords || 0; const pageCount = Math.max(1, Math.ceil(total / PER_SITEMAP)); return Array.from({ length: pageCount }, (_, id) => ({ id })); } catch { return [{ id: 0 }]; } } export default async function sitemap({ id }) { if (!API_URL) return []; try { const res = await fetch(`${API_URL}/api/v1/clinics?page=${id + 1}&limit=${PER_SITEMAP}`, { next: { revalidate: 3600 }, }); if (!res.ok) return []; const json = await res.json(); const clinics = json?.data || []; return clinics .filter((c) => c?.uuid) .map((c) => ({ url: `${MAIN_DOMAIN}/clinic/${c.uuid}`, lastModified: new Date(), changeFrequency: 'weekly', priority: 0.7, })); } catch { return []; } }