gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
73.55k stars 7.38k forks source link

Set `outdir` (`imagesoutdir`) to the slugified value when rendering AsciiDoc diagrams. #10183

Open madhead opened 1 year ago

madhead commented 1 year ago

I have a small Hugo site using AsciiDoc (sources). I want to add diagrams to it.

This page helps a lot to set them up: https://gohugo.io/content-management/formats. What I have to do to get the diagrams working, is just adding a few lines to the config.yml:

 markup:
   tableOfContents:
     startLevel: 2
+  asciidocExt:
+    extensions:
+      - asciidoctor-diagram
+    workingFolderCurrent: true

After that the diagrams mostly work, but I've noticed an issue.

Take a look at this page: content/wiki/3D printing/_index.adoc. It's path on the filesystem is not slug-friendly: it contains spaces and upper case characters.

Hugo renders this page into a file named public/wiki/3d-printing/index.html. Basically, the path is slugified.

However, when it calls asciidoctor-diagram, the outdir is different and corresponds to the original *.adoc file path:

DEBUG 2022/08/19 02:26:46 Render page 🗜️ 3D printing to "/wiki/3d-printing/index.html"
INFO 2022/08/19 02:26:46 Rendering wiki/3D printing/_index.adoc  using asciidoctor args [-r asciidoctor-diagram --base-dir /home/madhead/Projects/wiki/content/wiki/3D printing -a outdir=/home/madhead/Projects/wiki/public/wiki/3D printing --no-header-footer --verbose -] ...

Note this:

As a result, I have two directories now:

image

What's even worse, is that the resulting HTML page is incorrect: it refers the image as if it were in the same directory:

<img src="diag-8ac9b322bf3e2e1e7b0df17f6f64d0a6.png" alt="Diagram" width="540" height="280"/>

As you might guess, the diagram is not shown on the page.

This issue exists only when the path of page source (the *.adoc file) is different from the resulting slug. If the page path is the same as it's own slugified path, then everything works correctly.

Is it possible to tune this behavior? I'd prefer the diagrams be rendered into slugified directories.

Reading the code didn't help me a lot, looks like here https://github.com/gohugoio/hugo/blob/f7e00c039ff3cea5f991b05c1e325666004cf129/markup/asciidocext/convert.go#L161 the path is pretty rigidly tied to the filepath.Dir(ctx.DocumentName) or filepath.Dir(ctx.Filename).

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open. If this is a feature request, and you feel that it is still relevant and valuable, please tell us why. This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.