import type { MetadataRoute } from "next"; import { apiFetch } from "@/lib/api"; import { appUrl } from "@/lib/siteConfig"; type Event = { id: string; updatedAt?: string; startDate: string }; export const revalidate = 3600; export default async function sitemap(): Promise { const base = appUrl.replace(/\/$/, ""); const staticEntries: MetadataRoute.Sitemap = [ { url: `${base}/`, changeFrequency: "daily", priority: 1 }, { url: `${base}/events`, changeFrequency: "daily", priority: 0.9 }, { url: `${base}/contact`, changeFrequency: "monthly", priority: 0.5 }, ]; let events: Event[] = []; try { events = await apiFetch("/api/events", { nextOptions: { next: { revalidate } } }); } catch { // Backend unreachable at build/revalidate time — ship the static entries only, // same degrade-gracefully posture as layout.tsx's getServerSettings. } const eventEntries: MetadataRoute.Sitemap = (events || []).map((e) => ({ url: `${base}/events/${e.id}`, lastModified: e.updatedAt ? new Date(e.updatedAt) : undefined, changeFrequency: "weekly", priority: 0.7, })); return [...staticEntries, ...eventEntries]; }