From c68102928848bed28b23150f89228ab84568f45a Mon Sep 17 00:00:00 2001 From: vcoppe Date: Mon, 30 Sep 2024 11:04:20 +0200 Subject: [PATCH] fix sitemap --- website/src/lib/sitemap.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/website/src/lib/sitemap.ts b/website/src/lib/sitemap.ts index 4116cae3..5c788e3e 100644 --- a/website/src/lib/sitemap.ts +++ b/website/src/lib/sitemap.ts @@ -2,29 +2,33 @@ import fs from 'fs'; import { glob } from 'glob'; import { languages } from '$lib/languages'; +function getURLForLanguage(lang: string, path: string): string { + return `https://gpx.studio${lang === 'en' ? '' : `/${lang}`}${path}`; +} + function generateSitemap() { - const pages = glob.sync('**/*.html', { cwd: 'build' }); + const pages = glob.sync('**/*.html', { cwd: 'build' }).map((page) => `/${page}`); let sitemap = '\n'; sitemap += '\n'; pages.forEach((page) => { - const url = page.replace('.html', '').replace('index', ''); + const path = page.replace('/index.html', '').replace('.html', ''); - const rootDir = url.split('/')[0]; - if (url.includes('embed') || url.includes('404') || languages[url] || languages[rootDir]) { + const rootDir = path.split('/')[1]; + if (path.includes('embed') || path.includes('404') || languages[path] || languages[rootDir]) { // Skip localized pages return; } Object.keys(languages).forEach((language) => { sitemap += `\n`; - sitemap += ` https://gpx.studio/${language === 'en' ? '' : language + '/'}${url}\n`; + sitemap += ` ${getURLForLanguage(language, path)}\n`; Object.keys(languages).forEach((alternate) => { if (alternate === language) return; - sitemap += ` \n`; + sitemap += ` \n`; }); sitemap += `\n`;