From 4ab23c8de1854b81f1831a7b39bd4e13dcd5b5ae Mon Sep 17 00:00:00 2001 From: Louis-Maxime Piton Date: Tue, 20 May 2025 17:46:11 +0200 Subject: [PATCH] Local assets working for Windows --- site/src/libs/examples.ts | 4 ++-- site/src/libs/path.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) 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)