question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support prepending of base url in markdown image paths

See original GitHub issue

🚀 Feature

I want to display images without using JSX in my Markdown code

![my image](/static/img/...)

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!):

Bildschirmfoto 2020-05-07 um 11 12 49 Bildschirmfoto 2020-05-07 um 11 12 53

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

Bildschirmfoto 2020-05-07 um 11 15 52

and even the HTML meta tags which is a SEO-killer:

Bildschirmfoto 2020-05-07 um 11 16 27

Please consider adding this functionality to Docusaurus. I’d be happy to help!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:24 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
slorbercommented, Feb 10, 2021

Hi @dulinriley

You need to run yarn add url-loader -D to the website folder and it works.

I think it fails because the md image paths are converted require() calls, needing node_modules/url-loader to exist, but it does not exist because it’s just a transitive dependency of Docusaurus. Will try to see how to fix that.

2reactions
slorbercommented, Aug 19, 2020

@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 website/node_modules, as it’s likely to be useful for those migrating from docusaurus v1 and keeping docs in place.

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prepend a url to all relative image links in a markdown ...
I'm using _ as the pattern delimiters instead of the more common / , because it means I don't have to escape every...
Read more >
Need help understanding url conversions - support - HUGO
Hi I'm struggling to understand how URLs are changed by the likes of absURL or relURL.
Read more >
Markdown Tips | Markdown Lessons Project - GitHub Pages
Inside the pre-pending moustache or Liquid Variable Statement, the object site may be placed with a reference to the site baseurl property via...
Read more >
Static Assets - Docusaurus
In Markdown, you can stick to using absolute paths when writing links or images in Markdown syntax because Docusaurus handles them as require ......
Read more >
Configuring Site Relative Base Paths - Markdown Monster
the images are unlikely to render properly in the Preview, because MM can't interpret the / or ~/ root path without some help....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found