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:
base-dir: /home/madhead/Projects/wiki/content/wiki/3D printing
outdir: /home/madhead/Projects/wiki/public/wiki/3D printing
As a result, I have two directories now:

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
|
args = append(args, "--base-dir", contentDir, "-a", "outdir="+outDir) |
the path is pretty rigidly tied to the
filepath.Dir(ctx.DocumentName) or
filepath.Dir(ctx.Filename).
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: trueAfter 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, theoutdiris different and corresponds to the original*.adocfile path:Note this:
base-dir:/home/madhead/Projects/wiki/content/wiki/3D printingoutdir:/home/madhead/Projects/wiki/public/wiki/3D printingAs a result, I have two directories now:
What's even worse, is that the resulting HTML page is incorrect: it refers the image as if it were in the same directory:
As you might guess, the diagram is not shown on the page.
This issue exists only when the path of page source (the
*.adocfile) 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
hugo/markup/asciidocext/convert.go
Line 161 in f7e00c0
filepath.Dir(ctx.DocumentName)orfilepath.Dir(ctx.Filename).