import type { MetadataRoute } from 'next' const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || 'https://example.com' /** * Next.js 14 sitemap.ts — automatically served at /sitemap.xml. * * Static routes are hard-coded. Blog post slugs would ideally come from * an API/DB fetch; since this CMS is localStorage-based we leave an * extensible placeholder. * * To add dynamic blog posts, replace the empty `dynamicRoutes` array with * an API call, e.g.: * const posts = await fetch(`${SITE_URL}/api/posts`).then(r => r.json()) * const dynamicRoutes = posts.map(p => ({ ... })) */ export default async function sitemap(): Promise { const now = new Date() // ── Static public routes ──────────────────────────────────────────────── const staticRoutes: MetadataRoute.Sitemap = [ { url: `${SITE_URL}/`, lastModified: now, changeFrequency: 'weekly', priority: 1.0, }, { url: `${SITE_URL}/blog`, lastModified: now, changeFrequency: 'daily', priority: 0.9, }, { url: `${SITE_URL}/gallery`, lastModified: now, changeFrequency: 'weekly', priority: 0.7, }, { url: `${SITE_URL}/about`, lastModified: now, changeFrequency: 'monthly', priority: 0.6, }, { url: `${SITE_URL}/contact`, lastModified: now, changeFrequency: 'monthly', priority: 0.5, }, ] // ── Dynamic blog post routes (extend when you have an API) ─────────────── // const posts = await fetchPublishedPosts() // const dynamicRoutes: MetadataRoute.Sitemap = posts.map((post) => ({ // url: `${SITE_URL}/blog/${post.slug}`, // lastModified: new Date(post.updatedAt ?? post.publishedAt), // changeFrequency: 'monthly', // priority: 0.8, // })) return [ ...staticRoutes, // ...dynamicRoutes, ] }