Diagrams
Use a fenced code block to embed an SVG image of a diagram in your Doks site using the free Kroki service.
Unlike JavaScript solutions that require client-side rendering, this approach embeds an SVG image in your page.
Hugo supports GoAT diagrams (ASCII diagrams) natively.
Overview
Kroki generates diagrams from textual descriptions, and provides a unified API with support for D2, Mermaid, PlantUML, and other diagram types.
You can create:
- Block diagrams
- Container diagrams
- Gantt diagrams
- Mind maps
- Sequence diagrams
- UML diagrams
- Word clouds
- And more…
Visit the Kroki site for more examples.
Examples
D2
Mermaid
PlantUML
Performance
The render hook calls Hugo’s resources.GetRemote
function to request the SVG image from the Kroki API. Hugo caches the result, and invalidates the cache when (a) you edit the LaTeX markup, or (b) the cache expires.
To optimize performance in a CI/CD environment such as Cloudflare Pages, GitHub Pages, or Netlify, you should:
Edit your site configuration to store the
getresource
cache in the project’sresources
directory, setting the cache to never expire:Check the
resources
directory into source control.
In this configuration, Hugo will use the cached resources when building your site locally and remotely, invalidating the cache when you change the LaTeX markup.