updates 33.1 139
This commit is contained in:
69
docs/graphs/render.sh
Executable file
69
docs/graphs/render.sh
Executable file
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env bash
|
||||
# Render every .dot through every theme.
|
||||
#
|
||||
# ./render.sh # all graphs, all themes
|
||||
# ./render.sh lucid # one theme
|
||||
# ./render.sh dark system_overview
|
||||
#
|
||||
# The sources carry structure and meaning; themes/*.gvpr carry palette. gvpr
|
||||
# rewrites the parsed graph, so it wins over anything a .dot sets inline — which
|
||||
# is what lets one source render in several looks without being edited.
|
||||
#
|
||||
# Output naming: the default theme writes <name>.svg, because that is what
|
||||
# docs/data/en/*.md already links to and those links should keep working. Every
|
||||
# other theme writes <name>.<theme>.svg.
|
||||
#
|
||||
# Why baked rather than CSS: both docs sites embed graphs with <img src=...>,
|
||||
# which makes the SVG a separate document that the page's stylesheet cannot
|
||||
# reach. Colour has to be in the file.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
DEFAULT_THEME=dark
|
||||
|
||||
if ! command -v dot >/dev/null 2>&1 || ! command -v gvpr >/dev/null 2>&1; then
|
||||
echo "graphviz not found — install with: sudo apt install graphviz" >&2
|
||||
echo "(the committed .svg files already work; this is only needed to re-render)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
theme_arg="${1:-}"
|
||||
graph_arg="${2:-}"
|
||||
|
||||
themes=()
|
||||
if [ -n "$theme_arg" ]; then
|
||||
if [ ! -f "themes/${theme_arg}.gvpr" ]; then
|
||||
echo "no such theme: themes/${theme_arg}.gvpr" >&2
|
||||
echo "available: $(ls themes/*.gvpr 2>/dev/null | xargs -n1 basename | sed 's/\.gvpr$//' | tr '\n' ' ')" >&2
|
||||
exit 1
|
||||
fi
|
||||
themes=("$theme_arg")
|
||||
else
|
||||
for t in themes/*.gvpr; do themes+=("$(basename "$t" .gvpr)"); done
|
||||
fi
|
||||
|
||||
shopt -s nullglob
|
||||
sources=(*.dot)
|
||||
if [ -n "$graph_arg" ]; then
|
||||
sources=("${graph_arg%.dot}.dot")
|
||||
[ -f "${sources[0]}" ] || { echo "no such graph: ${sources[0]}" >&2; exit 1; }
|
||||
fi
|
||||
[ ${#sources[@]} -gt 0 ] || { echo "no .dot files here"; exit 0; }
|
||||
|
||||
for theme in "${themes[@]}"; do
|
||||
for src in "${sources[@]}"; do
|
||||
base="${src%.dot}"
|
||||
if [ "$theme" = "$DEFAULT_THEME" ]; then
|
||||
out="${base}.svg"
|
||||
else
|
||||
out="${base}.${theme}.svg"
|
||||
fi
|
||||
# One pipeline, so a gvpr failure fails the whole render rather than
|
||||
# silently writing a half-themed file.
|
||||
gvpr -c -f "themes/${theme}.gvpr" "$src" | dot -Tsvg -o "$out"
|
||||
printf " %-14s %s\n" "$theme" "$out"
|
||||
done
|
||||
done
|
||||
|
||||
echo
|
||||
echo "done — ${#sources[@]} graph(s) x ${#themes[@]} theme(s)"
|
||||
Reference in New Issue
Block a user