feat: init sitemaps generation

This commit is contained in:
swve 2024-09-26 23:29:05 +02:00
parent 09c0444284
commit 41a11c5f83
3 changed files with 88 additions and 3 deletions

View file

@ -21,6 +21,7 @@ export const config = {
* 5. all root files inside /public (e.g. /favicon.ico)
*/
'/((?!api|_next|fonts|umami|examples|[\\w-]+\\.\\w+).*)',
'/sitemap.xml',
],
}
@ -99,6 +100,29 @@ export default async function middleware(req: NextRequest) {
}
}
if (pathname.startsWith('/sitemap.xml')) {
let orgslug: string;
if (hosting_mode === 'multi') {
orgslug = fullhost
? fullhost.replace(`.${LEARNHOUSE_DOMAIN}`, '')
: (default_org as string);
} else {
// Single hosting mode
orgslug = default_org as string;
}
const sitemapUrl = new URL(`/api/sitemap`, req.url);
// Create a response object
const response = NextResponse.rewrite(sitemapUrl);
// Set the orgslug in a header
response.headers.set('X-Sitemap-Orgslug', orgslug);
return response;
}
// Multi Organization Mode
if (hosting_mode === 'multi') {
// Get the organization slug from the URL