From 08a9446744a7e9f8a71ea28d6a30a82cb14d4fe8 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Fri, 3 Mar 2023 10:44:28 -0500 Subject: [PATCH] fix: forward slash. --- packages/integrations/markdoc/src/index.ts | 6 +++--- packages/integrations/markdoc/src/utils.ts | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/integrations/markdoc/src/index.ts b/packages/integrations/markdoc/src/index.ts index 2fc4021df..8e70187de 100644 --- a/packages/integrations/markdoc/src/index.ts +++ b/packages/integrations/markdoc/src/index.ts @@ -1,8 +1,8 @@ import type { AstroIntegration, AstroConfig } from 'astro'; -import { InlineConfig, normalizePath } from 'vite'; +import { InlineConfig } from 'vite'; import type { Config } from '@markdoc/markdoc'; import Markdoc from '@markdoc/markdoc'; -import { getAstroConfigPath, MarkdocError, parseFrontmatter } from './utils.js'; +import { prependForwardSlash, getAstroConfigPath, MarkdocError, parseFrontmatter } from './utils.js'; import { fileURLToPath } from 'node:url'; import fs from 'node:fs'; @@ -39,7 +39,7 @@ export default function markdoc(markdocConfig: Config = {}): AstroIntegration { validateRenderProperties(markdocConfig, config); const body = - getEntryInfo({ fileUrl: new URL('/' + normalizePath(id), 'file://'), contents: code }).body; + getEntryInfo({ fileUrl: new URL(prependForwardSlash(id), 'file://'), contents: code }).body; const ast = Markdoc.parse(body); const content = Markdoc.transform(ast, markdocConfig); diff --git a/packages/integrations/markdoc/src/utils.ts b/packages/integrations/markdoc/src/utils.ts index 9ef80e1bf..33746f53b 100644 --- a/packages/integrations/markdoc/src/utils.ts +++ b/packages/integrations/markdoc/src/utils.ts @@ -102,3 +102,10 @@ export function getAstroConfigPath(fs: typeof fsMod, root: string): string | und } } } + +/** + * @see 'astro/src/core/path.ts' + */ +export function prependForwardSlash(path: string) { + return path[0] === '/' ? path : '/' + path; +}