AVATEAM-IT-SYSTEMHAUS / mkdocs-kroki-plugin

MkDocs plugin for Kroki-Diagrams
MIT License
46 stars 28 forks source link

`None` being prepended to relative path for downloaded images #39

Closed markstickley closed 9 months ago

markstickley commented 1 year ago

Plugin version: 0.6.1

mkdocs.yaml:

site_name: 'my-site'

nav:
  - Home: index.md
  - Development: development.md

plugins:
  - techdocs-core
  - kroki:
      DownloadImages: true
      DownloadDir: "images/kroki_generated"

Generated image tag:

<img alt="Kroki" src="Noneimages/kroki_generated/krokitest-577414e8fb4a6f6ddb993d1827fd6937.svg" />

Note that without the DownloadDir config option, the src is just Nonekrokitest-577414e8fb4a6f6ddb993d1827fd6937.svg

The svg is being generated and saved just fine, it's the html img tag that has the problem.

markstickley commented 1 year ago

Further investigations lead me to conclude that when the mkdocs site_url is not set explicitly (as in my case) config.get is not returning the falsey value expected here and so the default of / is not being set. I guess it's somehow being set to None or a string value of "None" but as I haven't written python before this is way outside of my wheelhouse.

Interestingly even if this was fixed, it still wouldn't solve for my use case of needing a relative path to the image not based off the root folder (i.e. for a markdown file in the root I would need the img src path to be ../images/kroki_generated/filename.svg). With my settings the last version that did that the way I expected was 0.3.0... But that's out of scope for this issue I think.

BasKloetIS commented 1 year ago

I agree that this is a bug and to be honest, I think the fallback value for the site_url should be "" instead of "/", so relative urls keep working. A workaround that worked for me was to add the following to my mkdocs.yml: site_url: ""

This fixes the problem with the images, while still keeping the site as a whole functional.

625dennis commented 1 year ago

Like @markstickley says, fix doesn't resolve relative path for image. Workaround doesn't work for relative paths. Would be great if downloaded images generated the correct relative path.

For those interested, an absolute path/url is needed for site_url if you are using nested directories. Not the best solution when trying to test mkdocs-kroki-plugin build step locally