mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-26 01:33:02 +00:00
replace require() by new URL()
This commit is contained in:
parent
af7acc9e04
commit
ef727ac013
|
|
@ -23,7 +23,10 @@ const createJSX = (node, pathUrl) => {
|
|||
const jsxNode = node;
|
||||
jsxNode.type = 'jsx';
|
||||
jsxNode.value = `<img ${node.alt ? `alt={"${escapeHtml(node.alt)}"} ` : ''}${
|
||||
node.url ? `src={require("${escapePath(pathUrl)}?${assetQuery}")}` : ''
|
||||
node.url
|
||||
? // see https://github.com/facebook/docusaurus/pull/4708#discussion_r624515715
|
||||
`src={new URL("${escapePath(pathUrl)}?${assetQuery}", import.meta.url)}`
|
||||
: ''
|
||||
}${node.title ? ` title="${escapeHtml(node.title)}"` : ''} />`;
|
||||
|
||||
if (jsxNode.url) {
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ function toAssetRequireNode({node, filePath, requireAssetPath}) {
|
|||
? relativeRequireAssetPath
|
||||
: `./${relativeRequireAssetPath}`;
|
||||
|
||||
const href = `require('${escapePath(
|
||||
const href = `new URL('${escapePath(
|
||||
relativeRequireAssetPath,
|
||||
)}?${assetQuery}')`;
|
||||
)}?${assetQuery}', import.meta.url).toString()`;
|
||||
const children = (node.children || []).map((n) => toValue(n)).join('');
|
||||
const title = node.title ? `title="${escapeHtml(node.title)}"` : '';
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,10 @@ or
|
|||
|
||||
<a
|
||||
target="_blank"
|
||||
href={require('../../assets/docusaurus-asset-example-pdf.pdf')}>
|
||||
href={new URL(
|
||||
'../../assets/docusaurus-asset-example-pdf.pdf',
|
||||
import.meta.url,
|
||||
).toString()}>
|
||||
Download this PDF
|
||||
</a>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue