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:
29
apps/scandic-web/app/sitemap/route.ts
Normal file
29
apps/scandic-web/app/sitemap/route.ts
Normal 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" },
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user