fix(seo): correct sitemap routes

This commit is contained in:
syntaxbullet
2026-07-31 19:03:07 +02:00
parent 0a19abd0b0
commit 07e9458aaf
13 changed files with 515 additions and 61 deletions

View File

@@ -3,28 +3,22 @@ import { getPayload } from 'payload'
import config from '@payload-config'
import { unstable_cache } from 'next/cache'
import { getPublicPublishedQueryOptions } from '@/utilities/publicationQuery'
import { createSitemapEntry, pageSitemapPath, type SitemapEntry } from '@/utilities/sitemapRoutes'
const getPagesSitemap = unstable_cache(
async () => {
const payload = await getPayload({ config })
const SITE_URL =
process.env.NEXT_PUBLIC_SERVER_URL ||
process.env.VERCEL_PROJECT_PRODUCTION_URL ||
'https://example.com'
const results = await payload.find({
collection: 'pages',
overrideAccess: false,
draft: false,
...getPublicPublishedQueryOptions(),
depth: 0,
limit: 1000,
pagination: false,
where: {
_status: {
equals: 'published',
},
},
select: {
slug: true,
spaPath: true,
updatedAt: true,
},
})
@@ -32,15 +26,8 @@ const getPagesSitemap = unstable_cache(
const dateFallback = new Date().toISOString()
const sitemap = results.docs
? results.docs
.filter((page) => Boolean(page?.slug))
.map((page) => {
return {
loc: page?.slug === 'home' ? `${SITE_URL}/` : `${SITE_URL}/${page?.slug}`,
lastmod: page.updatedAt || dateFallback,
}
})
: []
.map((page) => createSitemapEntry(page, pageSitemapPath(page), dateFallback))
.filter((entry): entry is SitemapEntry => Boolean(entry))
return sitemap
},