-
-
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
Support prepending of base url in markdown image paths #2724
Comments
To get around this, you can override the |
Hey @yangshun I'd be happy to work on this, but since the syntax of markdown is already pretty well defined, it would be a shame to have to use a different one. Would it be out of the question to change the default to always prepend the baseUrl? I imagine it's much more common than wanting to link to "outside" of the docusaurus site. You could still do that by using tags like the example above if you want to. Or if not that, maybe an option you can set (possibly in docusaurus.config.js) to toggle this behaviour? |
Linking to external images would work regardless of the automatic pre-use of useBaseUrl: |
Hey, this issue is already solved imho, you can use relative image paths (and colocate the image to its doc too, if needed): It uses webpack file-loader under the hook, which also provides nice benefits: we can now detect bad image paths at compile time, + add a hash to the image URL so that it can be cashed more aggressively. I don't like useBaseUrl either, and would like to deprecate it. Can we close this PR? |
Ah ok, thanks, I'll give that a go :) I was trying to use relative images today but didn't realise you had to import them, so the build would fail unless I prepended them with |
hmmm, this is surprising because url loader is a core dependency, and is indeed a required dep for this feature to work. Are you using something like yarn 2, pnp or something else? Did do yarn install? Can you run It may be because one of our package does not expose directly it as a direct dependency. Was precisely working on a bugfix of this part, we'll see in next release if it works better for you. |
Yup, this is apparently solved indeed. We can close it IMO :) |
@jknoxville is it working for you? How did you find about |
@slorber sorry for the delay getting back to you. This is the build error I get if I use a markdown image without importing that particular image with both the following syntax:
(where poisson.png is a file in the same dir as the markdown file referring to it)
I'm using yarn 1.17.0, the one that runs as standard at facebook. I think the So speaking for myself, I still can't get any images to work using the markdown syntax. Tried on versions 58 and 61. To clarify, I'd be happy with the restriction to only use absolute paths instead, but they don't currently get the baseUrl prepended. |
This is weird These features are new so don't stay on alpha 58. What gives Can you create a small repro? Maybe try to remove the .docusaurus folder? |
Thanks for the help @slorber I regenerated the yarn.lock, and verified that it only contains v61 of any docusaurus packages, still the same thing. However, I tried out using relative markdown images on the docusaurus website itself, and it works, so I can agree with you that relative images do in fact work and this issue can be closed :) there's just clearly something wrong with this other docusaurus installation, but as far as I know thats unrelated to this issue. |
Great to know :) This is weird that it doesn't work on your website. Unfortunately without a repro it will be hard to troubleshot. |
@jknoxville I think @anshulrgoyal found out why the url loader does not work in your case, because the docs are outside of the website, and it does not resolve against parent/website/node_modules but against parent/node_modules. Adding URL loader in the parent is likely to solve this issue, but we'll also add resolution to I've seen this on Flipper: https://github.com/facebook/flipper/blob/master/website/docusaurus.config.js#L118 Did you migrate from v1 and decided to keep the docs in place instead of moving them? |
Yes exactly, I didn't see a reason to move them, but can do if it's necessary. I'd prefer that than having to turn the parent into a JS package. |
No it should be supported, we don't want to force users to move folders as it seems it can messup a bit the git history 🤪 we are currently experiencing that in RN website migration |
@slorber I'm running into this issue as well for the Hermes website, using "@docusaurus/[email protected]". Tried upgrading to alpha.70 as well and it didn't fix the issue. Hermes's docusaurus directory is here: https://github.com/facebook/hermes/tree/master/website
And it had the same Has this "not subdirectory of website" issue been fixed yet? Has an updated docusaurus been pushed? |
Hi @dulinriley I don't see the /doc folder in that repo 😅 If the image is in /static, my reco would to to avoid relative paths. These paths are useful when you want to colocate assets close to the doc (possibly translate/vesion them alongside the markdown files). If a file is in /static/img/foo.png, you should just use I can give more advice if you give me more concrete file URLs to look at, or create a repro using http://new.docusaurus.io/ |
The link is to a subdirectory of the Hermes repo. If you go one directory up from I can try putting them in the static directory instead and see if that fixes my problem |
I moved the images to the
That's adding the following to the docs/IR.md file: ![Test](/img/favicon.ico) (and after moving the directory |
@dulinriley can you show me a failing PR/branch so that I see what you are attempting to do exactly? |
@slorber I made a PR for this: https://github.com/dulinriley/hermes/pull/1 That PR contains the error message. For that PR I also tried moving the |
Hi @dulinriley You need to run I think it fails because the md image paths are converted require() calls, needing |
Is it just a dev dependency, or is it needed for the production website build? |
yes sorry it is useful to run yarn build if you build on the CI (so remove -D) |
🚀 Feature
I want to display images without using JSX in my Markdown code
and have Docusaurus modify the image
src
using the project's baseUrl.Have you read the [Contributing Guidelines on issues]
Yes
Motivation & Pitch
Currently, it's recommended to link to an image using:
import useBaseUrl from '@docusaurus/useBaseUrl' <img alt="ORY Oathkeeper with Prometheus and Grafana" src={useBaseUrl('img/docs/grafana.png')} />
This has several disadvantages. First it doesn't work with native markdown and thus looks confusing when browsing the docs on e.g. GitHub (both in preview and raw view!):
Second it's hard to understand for people who don't know Docusaurus. None of our docs contributors has figured out how to use this correctly. This means that the time to merge for docs changes goes up and frustrates both maintainers as well as contributors.
Third it breaks previews. Assuming that - as it's documented - the import is always the first element, we get previews in Slack
and even the HTML meta tags which is a SEO-killer:
Please consider adding this functionality to Docusaurus. I'd be happy to help!
The text was updated successfully, but these errors were encountered: