I am still new to Hugo, so still trying to get a feel for everything. One challenge I ran into has to do with including diagrams in my posts. So I write my posts in Asciidoc, and there are some nice tools like asciidoctor-diagrams
that allow me to include graphviz, mermaid, or planetuml diagrams in the final pdf or html pages.
It seems that Hugo does not currently support running asciidoctor-diagrams
when calling the asciidoctor
tool to compile posts. So various people have posted about scripts they developed to get around this limitation. I include a few examples of these scripts below. BUT, my question is really whether there is a consensus on the best way to do this now? I was not sure what the latest thinking or approach was. Each of these scripts do similar things but in slightly different ways. So I figured I would ask.
Once post had a script like this:
#!/bin/bash
if [ -f /usr/local/bin/asciidoctor ]; then
ad="/usr/local/bin/asciidoctor"
else
ad="/usr/bin/asciidoctor"
fi
$ad -v -B . -r asciidoctor-diagram -a icons=font -a docinfo=shared -a nofooter -a sectanchors -a experimental=true -a figure-caption! -a source-highlighter=highlightjs -a toc-title! -a stem=mathjax - | sed -E -e "s/img src=\"([^/]+)\"/img src=\"\/diagram\/\1\"/"
mkdir -p static/diagram
if ls *.svg >/dev/null 2>&1; then
mv -f *.svg static/diagram
fi
if ls *.png >/dev/null 2>&1; then
mv -f *.png static/diagram
fi
Another post looked like this using safe
mode:
#!/bin/bash
ARGS=$(echo "$@" | sed -e 's/--safe//')
/usr/bin/asciidoctor_real -r asciidoctor-html5s -r asciidoctor-diagram -b html5s $ARGS
And there was also a pull request on this topic as well.
gohugo PR #7281
But I don’t really know which approaches work, is there any consensus around the best approach, etc.
@muenchhausen if you have any thoughts, please chime in since the pull request was created by you.