MCPcopy
hub / github.com/facebook/docusaurus / createAssetValueCode

Function createAssetValueCode

packages/docusaurus-mdx-loader/src/utils.ts:39–56  ·  view source on GitHub ↗
(assetValue: unknown)

Source from the content-addressed store, hash-verified

37
38 // TODO implementation can be completed/enhanced
39 function createAssetValueCode(assetValue: unknown): string | undefined {
40 if (Array.isArray(assetValue)) {
41 const arrayItemCodes = assetValue.map(
42 (item: unknown) => createAssetValueCode(item) ?? 'undefined',
43 );
44 return `[${arrayItemCodes.join(', ')}]`;
45 }
46 // Only process string values starting with ./
47 // We could enhance this logic and check if file exists on disc?
48 if (typeof assetValue === 'string' && assetValue.startsWith('./')) {
49 // TODO do we have other use-cases than image assets?
50 // Probably not worth adding more support, as we want to move to Webpack 5 new asset system (https://github.com/facebook/docusaurus/pull/4708)
51 return `require("${inlineMarkdownAssetImageFileLoader}${escapePath(
52 assetValue,
53 )}").default`;
54 }
55 return undefined;
56 }
57
58 const assetEntries = Object.entries(assets);
59

Callers 1

createAssetsExportCodeFunction · 0.85

Calls 1

escapePathFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…