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
Question about whether the relative path is base on current working dir or current md file? #8
Comments
Hi @RunSimple42, if I'm not mistaken, the current behavior is that the relative path is based on project root. That's how Eleventy-img plugin is resolving relative path too. If I understand correctly, when you're using a reference to an image the path is resolved against CWD, but what you would like is to not have to do |
Would you have an example I could play with? Thanks! |
Hi @RunSimple42, I'm rereading my comment and I believe that I answered a little quickly here and got a little confused. By default this plugin is resolving relative path based on the eleventy-img |
You could try this repo: https://github.com/tianjianchn/markdown-it-eleventy-img-relative-path-issue , after running
Maybe we could add an option to allow user to change this behavior? Place the images next to md file might be more intuitive and easy to manage. |
I'll look at it a little later. Thanks for your comment. This might be related to |
OK, I had time to play with @tianjianchn reproduction repo and it appears that my first comment was right in the end: relative paths are based on project root which is where the plugin is defined. So for instance, in @tianjianchn example, to reference - posts
- hello
- index.md
- hello.jpeg You have to do: <!-- posts/hello/index.md -->
![](./posts/hello/hello.jpeg)
<!-- OR -->
![](posts/hello/hello.jpeg)
<!-- The relative path is resolved against project root --> I, personally, never found that behavior to be problematic. I guess it always felt natural to me. I'm not sure it's explicit in the README though and it probably should (note to self). I know these things can be a matter of preference and I'm not against providing an opt-in |
For the record, I just found a blog post that tackle this very problem. The solution is very 11ty specific, but the principles are there! Maybe a good starting point. |
Funny enough, so far the test with the programmatic version of Eleventy doesn't yield any error. I'll keep testing! 😁 |
My bad, this is working as expected. 😂 |
Nice! Second this.
Yes, it is. As this blog's author said, he also made the output images being relative to post, not root. That's better for image SEO, which I didn't consider about ever. But it might break the behaviors of |
My idea would be to keep the current behavior as default and have a custom config property that could be switched off to get the other behavior. If it's not possible at all without breaking everything, I'll keep things as is which is completely functional, works for most use case and is aligned with the underlying tools used by |
I usually use markdown with image like that:
And in
hello.md
, image is referred like![](./hello.jpg)
.It's working in VSCode that what I think might be right, but not here. This package always try to resolve the src with cwd.
I was like to make a PR to fix this, but thought that may be a big break change. I'd like to listen your opinion about it, thanks.
The text was updated successfully, but these errors were encountered: