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 @@ -35,3 +35,7 @@
[![Clickable Docusaurus logo](./static/staticAssetImage.png)](/staticAssetImage.png)

[<span style={{color: "red"}}>Stylized link to asset file</span>](./asset.pdf)

[json](./data.json)

[static json](/staticjson.json)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hello": "world"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"static": ["json", 1]}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@ exports[`transformAsset plugin transform md links to <a /> 1`] = `
<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./static/staticAssetImage.png').default}><img alt={\\"Clickable Docusaurus logo\\"} src={require(\\"![CWD]/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=[CWD]/node_modules/file-loader/dist/cjs.js!./static/staticAssetImage.png\\").default} width=\\"200\\" height=\\"200\\" /></a>

<a target=\\"_blank\\" href={require('![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./asset.pdf').default}><span style={{color: \\"red\\"}}>Stylized link to asset file</span></a>

<a target=\\"_blank\\" href={require('./data.raw!=![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./data.json').default}>json</a>

<a target=\\"_blank\\" href={require('./static/staticjson.raw!=![CWD]/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./static/staticjson.json').default}>static json</a>
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ function toAssetRequireNode(node: Link, assetPath: string, filePath: string) {
const hash = parsedUrl.hash ?? '';
const search = parsedUrl.search ?? '';

const href = `require('${inlineMarkdownLinkFileLoader}${
const href = `require('${
// A hack to stop Webpack from using its built-in loader to parse JSON
path.extname(relativeAssetPath) === '.json'
? `${relativeAssetPath.replace('.json', '.raw')}!=`
: ''
}${inlineMarkdownLinkFileLoader}${
escapePath(relativeAssetPath) + search
}').default${hash ? ` + '${hash}'` : ''}`;
const children = stringifyContent(node);
Expand Down
8 changes: 8 additions & 0 deletions website/_dogfooding/_pages tests/_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

export default 1;
3 changes: 3 additions & 0 deletions website/_dogfooding/_pages tests/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hello": "world"
}
6 changes: 6 additions & 0 deletions website/_dogfooding/_pages tests/markdown-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ See [#3309](https://github.com/facebook/docusaurus/issues/3309)
- [pathname://../dogfooding/javadoc](pathname://../dogfooding/javadoc)

- [pathname://../dogfooding/javadoc/index.html](pathname://../dogfooding/javadoc/index.html)

## Linking to JSON

- [./script.js](./_script.js)

- [./data.json](./data.json)