From afe5fc0399b7b38805d2ec903ec994055d52e887 Mon Sep 17 00:00:00 2001 From: jnizet Date: Sun, 9 Nov 2025 12:41:51 +0100 Subject: [PATCH] fix(docs-infra): avoid double slash in sitemap urls Previously, the URLs in the generated sitemap contained double slashes between the host and the path. It's not the case anymore. fix #65022 --- .github/actions/deploy-docs-site/lib/sitemap.mts | 15 ++++++++++----- .github/actions/deploy-docs-site/main.js | 10 +++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/actions/deploy-docs-site/lib/sitemap.mts b/.github/actions/deploy-docs-site/lib/sitemap.mts index a16482a4a1a..19bec71e4e1 100644 --- a/.github/actions/deploy-docs-site/lib/sitemap.mts +++ b/.github/actions/deploy-docs-site/lib/sitemap.mts @@ -3,6 +3,10 @@ import {join} from 'path'; import {readFileSync, writeFileSync} from 'fs'; export async function generateSitemap(deployment: Deployment, distDir: string) { + const servingUrlWithoutEndingSlash = deployment.servingUrl.endsWith('/') + ? deployment.servingUrl.slice(0, -1) + : deployment.servingUrl; + /** Timestamp string used to of the last file update. */ const lastModifiedTimestamp = new Date().toISOString(); /** An object containing all of the routes available within the application. */ @@ -11,16 +15,17 @@ export async function generateSitemap(deployment: Deployment, distDir: string) { const sitemap = ` ${Object.keys(routes.routes) - .map( - (route) => ` + .map((route) => { + const routeWithoutLeadingSlash = route.startsWith('/') ? route.slice(1) : route; + return ` - ${deployment.servingUrl}${route} + ${servingUrlWithoutEndingSlash}/${routeWithoutLeadingSlash} ${lastModifiedTimestamp} daily 1.0 - `, - ) + `; + }) .join('')} `; writeFileSync(join(distDir, 'browser', 'sitemap.xml'), sitemap, 'utf-8'); diff --git a/.github/actions/deploy-docs-site/main.js b/.github/actions/deploy-docs-site/main.js index a1fb97d47ea..2e80fe574c6 100644 --- a/.github/actions/deploy-docs-site/main.js +++ b/.github/actions/deploy-docs-site/main.js @@ -48194,18 +48194,22 @@ async function getDeployments() { import { join as join4 } from "path"; import { readFileSync as readFileSync4, writeFileSync } from "fs"; async function generateSitemap(deployment, distDir) { + const servingUrlWithoutEndingSlash = deployment.servingUrl.endsWith("/") ? deployment.servingUrl.slice(0, -1) : deployment.servingUrl; const lastModifiedTimestamp = (/* @__PURE__ */ new Date()).toISOString(); const routes = JSON.parse(readFileSync4(join4(distDir, "prerendered-routes.json"), "utf-8")); const sitemap = ` - ${Object.keys(routes.routes).map((route) => ` + ${Object.keys(routes.routes).map((route) => { + const routeWithoutLeadingSlash = route.startsWith("/") ? route.slice(1) : route; + return ` - ${deployment.servingUrl}${route} + ${servingUrlWithoutEndingSlash}/${routeWithoutLeadingSlash} ${lastModifiedTimestamp} daily 1.0 - `).join("")} + `; + }).join("")} `; writeFileSync(join4(distDir, "browser", "sitemap.xml"), sitemap, "utf-8"); console.log(`Generated sitemap with ${Object.keys(routes.routes).length} entries.`);