Files
devvm/docs/layouts/_markup/render-codeblock-mermaid.html
w3cjandClaude Opus 5.5 89f26c5771 docs(site): draw the diagrams at build time with pele, no Mermaid JS
The docs site's 18 mermaid blocks are now drawn as SVGs before Hugo
builds the site, by docs/render-diagrams.mjs with pele 1.13.0, and
inlined by a render hook, so no page loads Mermaid's 5.5 MB script.

- docs/render-diagrams.mjs: finds each mermaid block in docs/content,
  draws it with pele in Departure Mono at 14px (a measurer from the
  font's metrics), and writes <key>.svg and <key>.json (its size) to
  the git-ignored docs/.build/diagrams. pele draws edge labels,
  messages and notes at round(14 * 0.875) = 12px with no option, so the
  measurer gives that text its 14px width and the script rewrites
  font-size="12" to 14 on each small-text group (pele-edge-labels,
  -notes, -boxes, -frames); a guard fails on any such group without
  font-size="12", or small text outside them, and a self-check, run
  whenever there's something to draw, renders an edge label, a message
  and a note and fails unless pele measured them at 12 and wrote their
  group with font-size="12". It also fails on a diagram without
  accTitle and accDescr, or on an indented block. A newline after each
  </text>, outside any text element, lets the search index see labels
  as separate words; screenshots of all 18 are byte-identical with and
  without it. (Newlines between a label's tspans would move centered
  lines, so a label's own lines stay joined in the index.)
- Caching: a block's key is sha256(salt + "\n" + text)[:16], the salt
  being sha256("pele <version>\n" + the script's text)[:16], written to
  diagrams/salt. The script keeps every drawing already there, draws
  only missing ones (written to .tmp and renamed), prunes files no key
  names, and touches the folder. docs:diagrams has sources (the pages,
  the script, package.json, the lock) and outputs (the folder), so mise
  skips an unchanged run, and runs npm ci only when the lock's SHA-256
  differs from docs/node_modules/.devvm-lock-sha256. An unchanged run:
  0.45-0.75 s before, 0.02 s now (0.09 s forced); one diagram changed:
  0.09 s. CI's check job caches ~/.npm keyed on the lock; the Docs
  workflow, which publishes, keeps no cache.
- docs/package.json and package-lock.json pin pele 1.13.0
  (sha512-Ie8UKY9x00MsuR3jO6AzUwzK2Z6MIV3Tf4EDdITiuk8Uaz8K7g0R082WqsqNaSU8DdgkrRvZThzhit83mi/uiw==).
- docs/layouts/_markup/render-codeblock-mermaid.html: in place of
  Hextra's hook, reads the salt, computes the key from it and .Inner,
  inlines the SVG from assets/diagrams (hugo.yaml mounts .build/diagrams
  there), sets the wrapper's contain-intrinsic-block-size to the
  diagram's height and --devvm-diagram-width to its width, and errorf's
  when a drawing or the salt is missing. layouts/_partials/scripts/
  mermaid.html and params.mermaid go.
- custom.css: .devvm-diagram with content-visibility: auto, and pele's
  --pele-* variables from the palette (subgraphs, lifelines and notes in
  the border color). A diagram wider than the text reaches into the
  article's right padding (1.5rem, 3rem from 768px) as far as it needs,
  then into the left padding for the rest, so it never covers the table
  of contents; wider than both, it scrolls. From about 1010px no diagram
  scrolls, the four wide ones included (proxy checks 751px, agent store,
  VM states, SSH agent); at 900px five scroll. With the table of
  contents shown, the proxy checks take 48px on the right and 31px on
  the left.
- mise.toml: docs:diagrams, which docs and lint:docs depend on.
  docs.yml: the next and release jobs install node and draw the
  diagrams; the release job only when the tag has the script, so older
  tags still build.
- scripts/bump.sh: bump_pele, named only, replaces bump_mermaid: npm
  install --save-exact --ignore-scripts in docs, then mise run
  docs:diagrams, whose self-check catches a pele that changed how it
  draws small text. TestBumpCoversPins finds docs/package.json's
  dependencies (npm:NAME); bump.txtar tests --check and the install.
  The header and hextra's note say the mermaid render hook replaces
  Hextra's mermaid hook, so check it still has that name.
- Every diagram gets an accTitle and accDescr, which pele makes the
  SVG's title and desc (aria-labelledby, aria-describedby). Staying
  safe's columns are written in reading order, as pele lays subgraphs
  out from left to right. The proxy checks' description names every
  branch, and a hand-placed <br> keeps "CA)" off a line of its own.
- AGENTS.md: the one Node script; no other build script is JavaScript,
  and no other npm package is installed outside mise's tools.
  Contributing's docs, tools and
  maintaining pages describe the drawing, the caching, the margin, the
  task and the bump.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 19:36:28 -07:00

22 lines
1.5 KiB
HTML

{{- /* A mermaid code block: the SVG that render-diagrams.mjs drew for it before the build, inlined, in
place of Hextra's hook, so no page loads Mermaid. hugo.yaml mounts the drawings' folder at
assets/diagrams. Each one's files are named for its key, the first 16 hex digits of the SHA-256 of
the salt the script wrote there (a hash of pele's version and the script), a newline and the
block's text. A missing one fails the build: run mise run docs:diagrams first. The wrapper gets the
diagram's height, for custom.css's content-visibility, which skips drawing a diagram until it nears
the screen, and its width, with which custom.css lets a wide one reach into the page's margin. */ -}}
{{- $salt := resources.Get "diagrams/salt" -}}
{{- if not $salt -}}
{{- errorf "%s: no drawings of the diagrams (diagrams/salt): run mise run docs:diagrams" .Position -}}
{{- else -}}
{{- $key := substr (sha256 (printf "%s\n%s" $salt.Content .Inner)) 0 16 -}}
{{- $svg := resources.Get (printf "diagrams/%s.svg" $key) -}}
{{- $size := resources.Get (printf "diagrams/%s.json" $key) -}}
{{- if not (and $svg $size) -}}
{{- errorf "%s: no drawing of this diagram (diagrams/%s.svg): run mise run docs:diagrams" .Position $key -}}
{{- else -}}
{{- $m := $size | transform.Unmarshal -}}
<div class="devvm-diagram" style="contain-intrinsic-block-size: auto {{ $m.height }}px; --devvm-diagram-width: {{ $m.width }}px">{{ $svg.Content | safeHTML }}</div>
{{- end -}}
{{- end -}}