File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66 */
77
88import path from 'path' ;
9- import url from 'url' ;
109import fs from 'fs-extra' ;
1110import {
1211 toMessageRelativeFilePath ,
@@ -207,27 +206,18 @@ async function processImageNode(target: Target, context: Context) {
207206 return ;
208207 }
209208
210- const parsedUrl = url . parse ( node . url ) ;
211- if ( parsedUrl . protocol || ! parsedUrl . pathname ) {
209+ if ( URL . canParse ( node . url ) ) {
212210 // pathname:// is an escape hatch, in case user does not want her images to
213211 // be converted to require calls going through webpack loader
214- if ( parsedUrl . protocol === 'pathname:' ) {
212+ if ( parseURLOrPath ( node . url ) . protocol === 'pathname:' ) {
215213 node . url = node . url . replace ( 'pathname://' , '' ) ;
216214 }
217215 return ;
218216 }
219217
220- // We decode it first because Node Url.pathname is always encoded
221- // while the image file-system path are not.
222- // See https://github.com/facebook/docusaurus/discussions/10720
223- const decodedPathname = decodeURIComponent ( parsedUrl . pathname ) ;
224-
225218 // We try to convert image urls without protocol to images with require calls
226219 // going through webpack ensures that image assets exist at build time
227- const localImagePath = await getLocalImageAbsolutePath (
228- decodedPathname ,
229- context ,
230- ) ;
220+ const localImagePath = await getLocalImageAbsolutePath ( node . url , context ) ;
231221 if ( localImagePath === null ) {
232222 node . url =
233223 context . onBrokenMarkdownImages ( {
Original file line number Diff line number Diff line change 66 */
77
88import path from 'path' ;
9- import url from 'url' ;
109import fs from 'fs-extra' ;
1110import {
1211 toMessageRelativeFilePath ,
@@ -209,23 +208,21 @@ async function processLinkNode(target: Target, context: Context) {
209208 return ;
210209 }
211210
212- const parsedUrl = url . parse ( node . url ) ;
213- if ( parsedUrl . protocol || ! parsedUrl . pathname ) {
211+ if (
212+ URL . canParse ( node . url ) ||
213+ parseURLOrPath ( node . url ) . protocol === 'pathname:'
214+ ) {
214215 // Don't process pathname:// here, it's used by the <Link> component
215216 return ;
216217 }
217- const hasSiteAlias = parsedUrl . pathname . startsWith ( '@site/' ) ;
218+ const hasSiteAlias = node . url . startsWith ( '@site/' ) ;
218219 const hasAssetLikeExtension =
219- path . extname ( parsedUrl . pathname ) &&
220- ! parsedUrl . pathname . match ( / \. (?: m d x ? | h t m l ) (?: # | $ ) / ) ;
220+ path . extname ( node . url ) && ! node . url . match ( / \. (?: m d x ? | h t m l ) (?: # | $ ) / ) ;
221221 if ( ! hasSiteAlias && ! hasAssetLikeExtension ) {
222222 return ;
223223 }
224224
225- const localFilePath = await getLocalFileAbsolutePath (
226- decodeURIComponent ( parsedUrl . pathname ) ,
227- context ,
228- ) ;
225+ const localFilePath = await getLocalFileAbsolutePath ( node . url , context ) ;
229226
230227 if ( localFilePath ) {
231228 await toAssetRequireNode ( target , localFilePath , context ) ;
You can’t perform that action at this time.
0 commit comments