You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the WebAssembly version of Graphviz is not exactly light (1.4MB at
the time of writing), and since it is a waste to let everybody re-render
the SVG client-side over and over again even though the diagram's
definition hasn't changed, let's add a script that performs that
rendering "on the server side" (more precisely: during deployment).
This script takes no arguments and post-processes the output of Hugo in
`public/`.
For performance reasons, it requires the list of files that contain
Graphviz diagrams. With this here site, it might not matter much because
there are only a handful images here. However, I want to reuse the same
method on git-scm.com where there _are_ thousands of files that do not
contain any Graphviz diagrams, and therefore it is a necessary
optimization to process only the files that _do_ contain Graphviz
diagrams.
To get that list, a new layout and page are added that Hugo processes,
identifyng said list of files and writing the result to
`public/diagram-list.html`.
Since this script runs via Node.JS and therefore lacks the convenient
built-in HTML parser of browser-based JavaScript engines, a prerequisite
is to run `npm install` so that the `node-html-parser` package is
available.
A note about the slightly inelegant way the `graphviz` class is added to
the generated SVGs: Sadly, `node-html-parser` is not smart enough to
handle `element.classList.add(...)` followed by `element.toString()`
correctly, and as a result the output would _not_ have the added class.
But there's always crude string processing to save the day.
Signed-off-by: Johannes Schindelin <[email protected]>
0 commit comments