Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import path from 'path';
import url from 'url';
import fs from 'fs-extra';
import {
toMessageRelativeFilePath,
Expand All @@ -15,6 +14,7 @@ import {
findAsyncSequential,
getFileLoaderUtils,
parseURLOrPath,
parseLocalURLPath,
} from '@docusaurus/utils';
import escapeHtml from 'escape-html';
import {imageSizeFromFile} from 'image-size/fromFile';
Expand Down Expand Up @@ -207,11 +207,11 @@ async function processImageNode(target: Target, context: Context) {
return;
}

const parsedUrl = url.parse(node.url);
if (parsedUrl.protocol || !parsedUrl.pathname) {
// pathname:// is an escape hatch, in case user does not want her images to
const localUrlPath = parseLocalURLPath(node.url);
if (!localUrlPath) {
// pathname:// is an escape hatch, in case the user does not want images to
// be converted to require calls going through webpack loader
if (parsedUrl.protocol === 'pathname:') {
if (parseURLOrPath(node.url).protocol === 'pathname:') {
node.url = node.url.replace('pathname://', '');
}
return;
Expand All @@ -220,7 +220,7 @@ async function processImageNode(target: Target, context: Context) {
// We decode it first because Node Url.pathname is always encoded
// while the image file-system path are not.
// See https://github.com/facebook/docusaurus/discussions/10720
const decodedPathname = decodeURIComponent(parsedUrl.pathname);
const decodedPathname = decodeURIComponent(localUrlPath.pathname);

// We try to convert image urls without protocol to images with require calls
// going through webpack ensures that image assets exist at build time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import path from 'path';
import url from 'url';
import fs from 'fs-extra';
import {
toMessageRelativeFilePath,
Expand All @@ -15,6 +14,7 @@ import {
findAsyncSequential,
getFileLoaderUtils,
parseURLOrPath,
parseLocalURLPath,
} from '@docusaurus/utils';
import escapeHtml from 'escape-html';
import logger from '@docusaurus/logger';
Expand Down Expand Up @@ -209,21 +209,22 @@ async function processLinkNode(target: Target, context: Context) {
return;
}

const parsedUrl = url.parse(node.url);
if (parsedUrl.protocol || !parsedUrl.pathname) {
const localUrlPath = parseLocalURLPath(node.url);
if (!localUrlPath) {
// Don't process pathname:// here, it's used by the <Link> component
return;
}
const hasSiteAlias = parsedUrl.pathname.startsWith('@site/');

const hasSiteAlias = localUrlPath.pathname.startsWith('@site/');
const hasAssetLikeExtension =
path.extname(parsedUrl.pathname) &&
!parsedUrl.pathname.match(/\.(?:mdx?|html)(?:#|$)/);
path.extname(localUrlPath.pathname) &&
!localUrlPath.pathname.match(/\.(?:mdx?|html)(?:#|$)/);
if (!hasSiteAlias && !hasAssetLikeExtension) {
return;
}

const localFilePath = await getLocalFileAbsolutePath(
decodeURIComponent(parsedUrl.pathname),
decodeURIComponent(localUrlPath.pathname),
context,
);

Expand Down
Loading