Commit e458803
committed
graphviz: optionally pre-generate the SVGs
The WebAssembly version of Graphviz is not exactly light (1.4 megabytes
at the time of writing). And it wasteful to let everybody re-render the
SVG client-side over and over again even though the diagram's definition
hasn't changed. So 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 other sites, it might not matter much because
there might only be a handful pages. However, on git-scm.com 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,
identifying 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 <johannes.schindelin@gmx.de>1 parent d9f9c5b commit e458803
File tree
5 files changed
+55
-1
lines changed- content
- layouts/_default
- script
5 files changed
+55
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
0 commit comments