45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { getServerSideSitemap } from 'next-sitemap'
|
|
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 results = await payload.find({
|
|
collection: 'pages',
|
|
...getPublicPublishedQueryOptions(),
|
|
depth: 0,
|
|
limit: 1000,
|
|
pagination: false,
|
|
select: {
|
|
slug: true,
|
|
spaPath: true,
|
|
updatedAt: true,
|
|
},
|
|
})
|
|
|
|
const dateFallback = new Date().toISOString()
|
|
|
|
const sitemap = results.docs
|
|
.map((page) => createSitemapEntry(page, pageSitemapPath(page), dateFallback))
|
|
.filter((entry): entry is SitemapEntry => Boolean(entry))
|
|
|
|
return sitemap
|
|
},
|
|
['pages-sitemap'],
|
|
{
|
|
tags: ['pages-sitemap'],
|
|
},
|
|
)
|
|
|
|
export async function GET() {
|
|
const sitemap = await getPagesSitemap()
|
|
|
|
return getServerSideSitemap(sitemap)
|
|
}
|