feat/SW-550 sitemap route

* feat(SW-550): Added rewrites to handle sitemap paths

* feat(SW-550): Added sitemap-index generation

* feat(SW-550): Added sitemap xml file generation

* feat(SW-550): Added feature flag 'HIDE_FOR_NEXT_RELEASE' to sitemap routes


Approved-by: Linus Flood
This commit is contained in:
Erik Tiekstra
2025-03-17 07:17:08 +00:00
parent f0b245bdfe
commit ca93046aad
6 changed files with 96 additions and 6 deletions

View File

@@ -0,0 +1,29 @@
import { notFound } from "next/navigation"
import { env } from "@/env/server"
import { getLastUpdated, getSitemapIds } from "@/utils/sitemap"
export const dynamic = "force-dynamic"
export async function GET() {
if (env.HIDE_FOR_NEXT_RELEASE) {
notFound()
}
const lastUpdated = await getLastUpdated()
const sitemaps = await getSitemapIds()
const urls = sitemaps.map(
(id) => `<sitemap>
<loc>${env.PUBLIC_URL}/sitemap-${id}.xml</loc>
<lastmod>${lastUpdated}</lastmod>
</sitemap>`
)
const sitemapIndexXML = `<?xml version="1.0" encoding="UTF-8"?>\n<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${urls.join("")}\n</sitemapindex>`
return new Response(sitemapIndexXML, {
headers: { "Content-Type": "text/xml" },
})
}