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'
|
||||
|
||||
/**
|
||||
* 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<MetadataRoute.Sitemap> {
|
||||
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,
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue