diff --git a/.changeset/fifty-otters-deliver.md b/.changeset/fifty-otters-deliver.md new file mode 100644 index 00000000..e56c3fb1 --- /dev/null +++ b/.changeset/fifty-otters-deliver.md @@ -0,0 +1,5 @@ +--- +'@jpmorganchase/mosaic-plugins': patch +--- + +Fixed DocumentAssetsPlugin not working on Windows diff --git a/packages/plugins/src/DocumentAssetsPlugin.ts b/packages/plugins/src/DocumentAssetsPlugin.ts index 55e04d19..34438643 100644 --- a/packages/plugins/src/DocumentAssetsPlugin.ts +++ b/packages/plugins/src/DocumentAssetsPlugin.ts @@ -57,9 +57,9 @@ function remarkRewriteImagePaths(newPrefix: string) { // Absolute URL or path, do nothing return; } else { - const isRelativePath = !isUrl(node.url) && !path.isAbsolute(node.url); + const isRelativePath = !isUrl(node.url) && !path.posix.isAbsolute(node.url); const assetPath = isRelativePath ? node.url : `./${node.url}`; - const resolvedPath = path.resolve(path.dirname(newPrefix), assetPath); + const resolvedPath = path.posix.resolve(path.posix.dirname(newPrefix), assetPath); node.url = resolvedPath; } } @@ -151,11 +151,7 @@ const DocumentAssetsPlugin: PluginType = { } } }, - async $afterSource( - pages, - { ignorePages, pageExtensions }, - { imagesPrefix = `${path.sep}images` } - ) { + async $afterSource(pages, { ignorePages, pageExtensions }, { imagesPrefix = `/images` }) { if (!pageExtensions.includes('.mdx')) { return pages; } @@ -168,7 +164,7 @@ const DocumentAssetsPlugin: PluginType = { const processor = unified() .use(remarkParse) .use(remarkMdx) - .use(remarkRewriteImagePaths, path.join(imagesPrefix, page.route)) + .use(remarkRewriteImagePaths, path.posix.join(imagesPrefix, page.route)) .use(remarkStringify); await processor .process(page.content)