fix(mdx-loader): prevent Open Graph images from being inserted as base64 (#9369)

Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
Zwyx 2023-10-05 20:21:27 +08:00 committed by GitHub
parent 15647a3abd
commit e17784effa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -28,7 +28,7 @@ import type {LoaderContext} from 'webpack';
type Pluggable = any; // TODO fix this asap type Pluggable = any; // TODO fix this asap
const { const {
loaders: {inlineMarkdownImageFileLoader}, loaders: {inlineMarkdownAssetImageFileLoader},
} = getFileLoaderUtils(); } = getFileLoaderUtils();
export type MDXPlugin = Pluggable; export type MDXPlugin = Pluggable;
@ -92,8 +92,9 @@ function createAssetsExportCode(assets: unknown) {
if (typeof assetValue === 'string' && assetValue.startsWith('./')) { if (typeof assetValue === 'string' && assetValue.startsWith('./')) {
// TODO do we have other use-cases than image assets? // TODO do we have other use-cases than image assets?
// Probably not worth adding more support, as we want to move to Webpack 5 new asset system (https://github.com/facebook/docusaurus/pull/4708) // Probably not worth adding more support, as we want to move to Webpack 5 new asset system (https://github.com/facebook/docusaurus/pull/4708)
const inlineLoader = inlineMarkdownImageFileLoader; return `require("${inlineMarkdownAssetImageFileLoader}${escapePath(
return `require("${inlineLoader}${escapePath(assetValue)}").default`; assetValue,
)}").default`;
} }
return undefined; return undefined;
} }

View file

@ -20,6 +20,7 @@ type FileLoaderUtils = {
file: (options: {folder: AssetFolder}) => RuleSetRule; file: (options: {folder: AssetFolder}) => RuleSetRule;
url: (options: {folder: AssetFolder}) => RuleSetRule; url: (options: {folder: AssetFolder}) => RuleSetRule;
inlineMarkdownImageFileLoader: string; inlineMarkdownImageFileLoader: string;
inlineMarkdownAssetImageFileLoader: string;
inlineMarkdownLinkFileLoader: string; inlineMarkdownLinkFileLoader: string;
}; };
rules: { rules: {
@ -74,6 +75,9 @@ export function getFileLoaderUtils(): FileLoaderUtils {
)}?limit=${urlLoaderLimit}&name=${fileLoaderFileName( )}?limit=${urlLoaderLimit}&name=${fileLoaderFileName(
'images', 'images',
)}&fallback=${escapePath(require.resolve('file-loader'))}!`, )}&fallback=${escapePath(require.resolve('file-loader'))}!`,
inlineMarkdownAssetImageFileLoader: `!${escapePath(
require.resolve('file-loader'),
)}?name=${fileLoaderFileName('images')}!`,
inlineMarkdownLinkFileLoader: `!${escapePath( inlineMarkdownLinkFileLoader: `!${escapePath(
require.resolve('file-loader'), require.resolve('file-loader'),
)}?name=${fileLoaderFileName('files')}!`, )}?name=${fileLoaderFileName('files')}!`,