fix: apply seo agent improvements to src/app/sitemap.ts
This commit is contained in:
parent
f91673c70a
commit
7713f8b27e
|
|
@ -3,33 +3,65 @@ import type { MetadataRoute } from 'next'
|
||||||
const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || 'https://example.com'
|
const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || 'https://example.com'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static sitemap entries. If you have a database/API you can
|
* Next.js 14 sitemap.ts — automatically served at /sitemap.xml.
|
||||||
* fetch dynamic slugs here — this function runs at build time
|
*
|
||||||
* (or on-demand with ISR).
|
* 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<MetadataRoute.Sitemap> {
|
||||||
|
const now = new Date()
|
||||||
|
|
||||||
|
// ── Static public routes ────────────────────────────────────────────────
|
||||||
const staticRoutes: MetadataRoute.Sitemap = [
|
const staticRoutes: MetadataRoute.Sitemap = [
|
||||||
{
|
{
|
||||||
url: SITE_URL,
|
url: `${SITE_URL}/`,
|
||||||
lastModified: new Date(),
|
lastModified: now,
|
||||||
changeFrequency: 'weekly',
|
changeFrequency: 'weekly',
|
||||||
priority: 1,
|
priority: 1.0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
url: `${SITE_URL}/blog`,
|
url: `${SITE_URL}/blog`,
|
||||||
lastModified: new Date(),
|
lastModified: now,
|
||||||
changeFrequency: 'daily',
|
changeFrequency: 'daily',
|
||||||
priority: 0.9,
|
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) ───────────────
|
||||||
* TODO: Replace with real dynamic post slugs fetched from your data source.
|
// const posts = await fetchPublishedPosts()
|
||||||
* Example:
|
// const dynamicRoutes: MetadataRoute.Sitemap = posts.map((post) => ({
|
||||||
* const posts = await fetch(`${SITE_URL}/api/posts`).then(r => r.json())
|
// url: `${SITE_URL}/blog/${post.slug}`,
|
||||||
* const postRoutes = posts.map(p => ({ url: `${SITE_URL}/blog/${p.slug}`, ... }))
|
// lastModified: new Date(post.updatedAt ?? post.publishedAt),
|
||||||
*/
|
// changeFrequency: 'monthly',
|
||||||
const exampleDynamicRoutes: MetadataRoute.Sitemap = []
|
// priority: 0.8,
|
||||||
|
// }))
|
||||||
|
|
||||||
return [...staticRoutes, ...exampleDynamicRoutes]
|
return [
|
||||||
|
...staticRoutes,
|
||||||
|
// ...dynamicRoutes,
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue