Skip to content

Commit d6ca5ba

Browse files
Docs: fix local assets path handling for Windows compatibility (#41485)
Co-authored-by: Julien Déramond <juderamond@gmail.com>
1 parent 374c8a1 commit d6ca5ba

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

site/src/libs/examples.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ function getExamplesAssetsRecursively(source: string, assets: string[] = []) {
5858
}
5959

6060
function sanitizeAssetPath(assetPath: string) {
61-
const matches = assetPath.match(/([^\/]+\/[^\/]+\.\w+)$/)
61+
const matches = assetPath.match(/([^\/\\]+[\/\\][^\/\\]+\.\w+)$/)
6262

6363
if (!matches || !matches[1]) {
6464
throw new Error(`Failed to get example asset path from path: '${assetPath}'.`)
6565
}
6666

67-
return matches[1]
67+
return matches[1].replaceAll('\\', '/')
6868
}
6969

7070
function isAliasedAstroInstance(page: AstroInstance): page is AliasedAstroInstance {

site/src/libs/path.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'node:fs'
22
import path from 'node:path'
33
import { getConfig } from './config'
4+
import { fileURLToPath } from 'node:url';
45

56
// The docs directory path relative to the root of the project.
67
export const docsDirectory = getConfig().docsDir
@@ -32,7 +33,7 @@ export function validateVersionedDocsPaths(distUrl: URL) {
3233

3334
for (const docsPath of generatedVersionedDocsPaths) {
3435
const sanitizedDocsPath = sanitizeVersionedDocsPathForValidation(docsPath)
35-
const absoluteDocsPath = path.join(distUrl.pathname, 'docs', docs_version, sanitizedDocsPath)
36+
const absoluteDocsPath = fileURLToPath(new URL(path.join( './docs', docs_version, sanitizedDocsPath), distUrl));
3637

3738
const docsPathExists = fs.existsSync(absoluteDocsPath)
3839

0 commit comments

Comments
 (0)