From: Louis-Maxime Piton Date: Sun, 25 May 2025 12:20:20 +0000 (+0200) Subject: Docs: fix local assets path handling for Windows compatibility (#41485) X-Git-Tag: v5.3.7~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d6ca5ba35b734115dfcedac615865f7a34e3d662;p=thirdparty%2Fbootstrap.git Docs: fix local assets path handling for Windows compatibility (#41485) Co-authored-by: Julien Déramond --- diff --git a/site/src/libs/examples.ts b/site/src/libs/examples.ts index b85cf5c56f..15596cd160 100644 --- a/site/src/libs/examples.ts +++ b/site/src/libs/examples.ts @@ -58,13 +58,13 @@ function getExamplesAssetsRecursively(source: string, assets: string[] = []) { } function sanitizeAssetPath(assetPath: string) { - const matches = assetPath.match(/([^\/]+\/[^\/]+\.\w+)$/) + const matches = assetPath.match(/([^\/\\]+[\/\\][^\/\\]+\.\w+)$/) if (!matches || !matches[1]) { throw new Error(`Failed to get example asset path from path: '${assetPath}'.`) } - return matches[1] + return matches[1].replaceAll('\\', '/') } function isAliasedAstroInstance(page: AstroInstance): page is AliasedAstroInstance { diff --git a/site/src/libs/path.ts b/site/src/libs/path.ts index ddcee5954a..a6ff100d51 100644 --- a/site/src/libs/path.ts +++ b/site/src/libs/path.ts @@ -1,6 +1,7 @@ import fs from 'node:fs' import path from 'node:path' import { getConfig } from './config' +import { fileURLToPath } from 'node:url'; // The docs directory path relative to the root of the project. export const docsDirectory = getConfig().docsDir @@ -32,7 +33,7 @@ export function validateVersionedDocsPaths(distUrl: URL) { for (const docsPath of generatedVersionedDocsPaths) { const sanitizedDocsPath = sanitizeVersionedDocsPathForValidation(docsPath) - const absoluteDocsPath = path.join(distUrl.pathname, 'docs', docs_version, sanitizedDocsPath) + const absoluteDocsPath = fileURLToPath(new URL(path.join( './docs', docs_version, sanitizedDocsPath), distUrl)); const docsPathExists = fs.existsSync(absoluteDocsPath)