Static Manual Generator Recipe: Token Ranking, Theme, and Media
Building a static manual that can be searched from an ordinary folder: media paths that never 404, token ranking, a dark theme, and a caption contract.
TL;DR
Images broke on deeper pages because file:// reads slash paths as filesystem paths, so compute relative paths at build time with path.relative(). Search ships as a plain script into IndexedDB with weighted scoring, versioned via the manifest's capturedAt. Theme lives harmlessly in localStorage, captions enforce per group, and output is a plain folder with index and PDF.
The manual generator finished its run, and the first page I opened showed the tour steps normally: the add-dialog image, the edit-dialog image, everything rendered. Then I opened a group page sitting one level deeper, and every image on it had turned into a broken icon. No error message in the terminal. The build still passed.
My first theory: set the image address from the root, say /media/shot-1.png, so the value stays the same no matter how deep the page sits. That theory was wrong. Under the file:// protocol there is no web root, and an address starting with a slash is read as a filesystem path instead. The fix is to compute the relative path from the page's own directory to the media folder. In Node.js, path.relative() takes two absolute paths and returns the relative path from the first to the second [4].
const path = require('node:path');
// Straight from the official Node.js docs [4]
path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb');
// Returns: '../../impl/bbb'The page.html file lives inside features/<group>/, which puts the media folder above it. The ../../ value from the example above is exactly the shape a manual page needs: one path.relative() call at build time, and images never 404 again regardless of page depth.
Search whose data is built along with it
This manual has to open the simplest way possible, by clicking the HTML file straight from its folder. The consequences I already worked through in the article about fetch being rejected on file://: search data must not be fetched, it ships as a plain script file that assigns window.MANUAL_DOCS. What that article did not touch is the shape of the search engine itself.
Every group document goes into IndexedDB in an object store named docs keyed by group. IndexedDB was chosen because it stores structured objects that can be searched through indexes [1], not just string pairs. The database opens without a version number because its schema never changes [2]; only its contents do.
const request = indexedDB.open('manual-docs', 1);
request.onupgradeneeded = (e) =>
e.target.result.createObjectStore('docs', { keyPath: 'group' });
// Re-seed only when the manifest version changes
if (rows.length && rows.at(0).capturedAt === version) return render(rows);
store.clear();
docs.forEach((d) => store.put(d));Data invalidation uses a single marker: every record carries the manifest's capturedAt, and the local copy is discarded whenever its value differs from the newest manifest. One field, one decision, no extra synchronization logic.
Result scoring uses simple weights I set myself. A token matching the group name scores +3, one matching the admin or public URL scores +2, and one matching a step or its caption scores +1. The top twenty results get rendered, each linking to its group page.
let score = 0;
for (const token of tokens) {
if (hay.name.includes(token)) score += 3; // group name
if (hay.urls.includes(token)) score += 2; // admin + public
if (hay.steps.includes(token)) score += 1; // shot + caption
}There is no search library in this recipe. The data is small, and explainable weights beat a mysterious ordering when a staff member asks why a result came out where it did.
A dark theme that must not be load-bearing
The manual's color palette sits as CSS custom properties on :root, then gets overridden by a [data-theme=dark] rule [5]. The theme choice is stored in localStorage under the key manual-theme, and the toggle button simply swaps the theme attribute on the root element.
One limitation shapes the design decision here. For documents opened from file:, localStorage behavior is explicitly undefined and may vary between browsers [3]. So the division of labor is strict: a lost theme preference is harmless, while search data must live in IndexedDB. A preference that disappears is tolerable; a manual that loses its data is not.
The caption contract and per-group migration
The last part of this recipe is not about JavaScript at all, it is about honest content. The manifest carries a {shot, caption} pair for every step, and the caption explains what the image proves. A screenshot without a caption is not hidden: it still renders, complete with a marker that its caption is missing, so the gap stays visible to anyone reading.
The document level doc_version: 2 makes captions and the public-facing section mandatory, but enforcement applies per group. Old groups do not get blocked just because one new contract arrived. The public section splits out screenshots whose names start with public and shows them as proof that admin input is actually visible to visitors.
The generator's final output is an ordinary folder: group pages, an index.html with a search box, assets/, and a print.html converted to PDF through Chromium with a forced light theme. I chose this shape because a good manual is one anyone can open without asking a server for permission.