From 7713f8b27e65c9e1974b166fb0492cf56123e089 Mon Sep 17 00:00:00 2001 From: cupadev-admin Date: Mon, 9 Mar 2026 20:55:24 +0000 Subject: [PATCH] fix: apply seo agent improvements to src/app/sitemap.ts --- src/app/sitemap.ts | 64 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/src/app/sitemap.ts b/src/app/sitemap.ts index a985353..036c0d6 100644 --- a/src/app/sitemap.ts +++ b/src/app/sitemap.ts @@ -3,33 +3,65 @@ import type { MetadataRoute } from 'next' const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || 'https://example.com' /** - * Static sitemap entries. If you have a database/API you can - * fetch dynamic slugs here — this function runs at build time - * (or on-demand with ISR). + * 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 function sitemap(): MetadataRoute.Sitemap { +export default async function sitemap(): Promise { + const now = new Date() + + // ── Static public routes ──────────────────────────────────────────────── const staticRoutes: MetadataRoute.Sitemap = [ { - url: SITE_URL, - lastModified: new Date(), + url: `${SITE_URL}/`, + lastModified: now, changeFrequency: 'weekly', - priority: 1, + priority: 1.0, }, { url: `${SITE_URL}/blog`, - lastModified: new Date(), + 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, + }, ] - /** - * TODO: Replace with real dynamic post slugs fetched from your data source. - * Example: - * const posts = await fetch(`${SITE_URL}/api/posts`).then(r => r.json()) - * const postRoutes = posts.map(p => ({ url: `${SITE_URL}/blog/${p.slug}`, ... })) - */ - const exampleDynamicRoutes: MetadataRoute.Sitemap = [] + // ── 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, ...exampleDynamicRoutes] + return [ + ...staticRoutes, + // ...dynamicRoutes, + ] }