Docs: fix local assets path handling for Windows compatibility (#41485)

Co-authored-by: Julien Déramond <juderamond@gmail.com>
This commit is contained in:
Louis-Maxime Piton 2025-05-25 14:20:20 +02:00 committed by GitHub
parent 374c8a1e1f
commit d6ca5ba35b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View File

@ -58,13 +58,13 @@ function getExamplesAssetsRecursively(source: string, assets: string[] = []) {
} }
function sanitizeAssetPath(assetPath: string) { function sanitizeAssetPath(assetPath: string) {
const matches = assetPath.match(/([^\/]+\/[^\/]+\.\w+)$/) const matches = assetPath.match(/([^\/\\]+[\/\\][^\/\\]+\.\w+)$/)
if (!matches || !matches[1]) { if (!matches || !matches[1]) {
throw new Error(`Failed to get example asset path from path: '${assetPath}'.`) 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 { function isAliasedAstroInstance(page: AstroInstance): page is AliasedAstroInstance {

View File

@ -1,6 +1,7 @@
import fs from 'node:fs' import fs from 'node:fs'
import path from 'node:path' import path from 'node:path'
import { getConfig } from './config' import { getConfig } from './config'
import { fileURLToPath } from 'node:url';
// The docs directory path relative to the root of the project. // The docs directory path relative to the root of the project.
export const docsDirectory = getConfig().docsDir export const docsDirectory = getConfig().docsDir
@ -32,7 +33,7 @@ export function validateVersionedDocsPaths(distUrl: URL) {
for (const docsPath of generatedVersionedDocsPaths) { for (const docsPath of generatedVersionedDocsPaths) {
const sanitizedDocsPath = sanitizeVersionedDocsPathForValidation(docsPath) 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) const docsPathExists = fs.existsSync(absoluteDocsPath)