-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(v2): support for adding relative images and handling broken image links #3069
Conversation
Deploy preview for docusaurus-2 ready! Built with commit 5725d64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, this looks like a great POC and works fine.
We should at least do the following before merge:
- add some tests
- document dogfood this (ie use the feature on the "markdown features" doc page)
Also, one awesome thing is that we can avoid bad image paths at compilation time now.
I also wonder, what do you think of supporting both syntaxes?
![](./assets/docusaurus-asset-example-banner.png)
![](assets/docusaurus-asset-example-banner.png)
Also, what about supporting this for assets of the static folder too?
For example we could make this work:
![](/img/docusaurus.png)
And make this fail at compile time:
![](/img/docusaurusTypo.png)
That would be a nice feature and add more safety to the assets system
packages/docusaurus-mdx-loader/src/remark/relativePath/index.js
Outdated
Show resolved
Hide resolved
packages/docusaurus-mdx-loader/src/remark/relativePath/index.js
Outdated
Show resolved
Hide resolved
Now it will verify all the |
looks great, thanks! |
@anshulrgoyal thanks for this. I was using a post build step to manually copy over relative assets. However, I notice that all images are being rendered as base64 urls instead of referring the actual asset. Any clue if this is a feature I need to disable? |
Images are mostly loaded using url-loader. If there is a very big image then it will be loaded using file-loader. |
I see, let me figure out a way to disable this for our install. Thanks for the prompt response! |
There is no way to disable it. |
No, I mean in the core itself. Might make a PR if I can do it in a neat config friendly way. |
But why do u need to refer actual assets? |
Better for site performance. Assets get cached by our CDN while html does not (for a good reason). |
ok got it. |
This is the difference between file-loader vs url-loader. There's a minimum size threshold that we could expose as a configuration option. |
https://webpack.js.org/loaders/url-loader/ Currently, the limit is 10kb, this is also what Gatby uses and seems a reasonable default value, but we could allow the user to provide what he wants so that assets are not inlined as base64 uris. If you want to submit a PR, webpack/utils.ts#getFileLoaderUtils |
@slorber that's strange, I have a 276kb file here being loaded as base64 URI. Site: https://new.ethvigil.com/docs/ (running on alpha 59) |
ah yes, I see where this comes from. When transforming the md syntax, we explicitly request url loader to kick in (also permits to avoid conflicts with the ideal image plugin), with no config, so using the md image syntax will always lead to inlined base64 images :/ As a workaround you can use a require() calls for now, as it's documented in the md features page. Not sure yet what's the best solution to this problem :/ this may require a breaking change in the ideal image plugin so that we can use require calls without forcing a specific loader. @anshulrgoyal any idea? |
@slorber I can add config to specify loader. eg user can provide a function that will transform the argument of |
Not sure to understand what you mean sorry |
node.url
? `src={require("${userFunction(node.url)}").default}`
: '' |
Something like this but its not ideal |
I think we should find and very different solution. I'd probably prefer having require("./image.png") work out of the box, using the loader we defined in the config, and do something special for the ideal image plugin case, because it's this plugin that forces us to add loader in require calls in the first place. |
Is there a way to disable this? This just caused my CI documentation builds to fail; we aren't managing static assets in git and would prefer to route to them externally via nginx. We have a fairly robust caching setup backed by S3, and would rather continue to handle things that way. |
u can add
|
Yes, as I thought this new behavior would annoy some users, I've added the |
Np 👍 |
Motivation
Allow the use relative path for images. Closes #3057
Have you read the Contributing Guidelines on pull requests?
yes
Test Plan
Added tests