Skip to content

Commit

Permalink
Fix DocumentAssetsPlugin not working on Windows (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding authored Oct 23, 2024
1 parent 3bf9aae commit adfb33a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-otters-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@jpmorganchase/mosaic-plugins': patch
---

Fixed DocumentAssetsPlugin not working on Windows
12 changes: 4 additions & 8 deletions packages/plugins/src/DocumentAssetsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -151,11 +151,7 @@ const DocumentAssetsPlugin: PluginType<Page, DocumentAssetsPluginOptions> = {
}
}
},
async $afterSource(
pages,
{ ignorePages, pageExtensions },
{ imagesPrefix = `${path.sep}images` }
) {
async $afterSource(pages, { ignorePages, pageExtensions }, { imagesPrefix = `/images` }) {
if (!pageExtensions.includes('.mdx')) {
return pages;
}
Expand All @@ -168,7 +164,7 @@ const DocumentAssetsPlugin: PluginType<Page, DocumentAssetsPluginOptions> = {
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)
Expand Down

0 comments on commit adfb33a

Please sign in to comment.