fix(seo): correct sitemap routes
This commit is contained in:
@@ -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
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user