how does · unni-web

How does the Unni shared builder work?

Overview

shared/build.js is a zero-dependency Node script. It takes a site folder with content fragments and wraps every page in one shared shell: header, nav, footer, design tokens, analytics and Ko-fi links. A site never copies the shell.

Mechanics

  • shared/sites.json is the single source for site URLs, social links and analytics tokens.
  • A site provides site.json (key, title, description, optional per-page metadata), src/**/*.html (the <main> content) and styles/site.css.
  • The builder walks src/, and for every .html file:
    • looks up its title/description in site.json.pages;
    • computes {{BASE}} (./ at the root, ../ one level down) so nested pages still find the stylesheets;
    • fills {{ROOT_URL}}, {{GAMES_URL}}, … and other placeholders;
    • inserts the page into shared/layout/base.html.
  • Non-HTML files under src/ are copied unchanged to dist/ (fonts, images, downloads).
  • buildSite(dir, { content }) lets a site render its own content first. unni-portfolio uses it to turn data/projects.json into cards.

Example

sites/root/src/license/index.html becomes sites/root/dist/license/index.html. Because it sits one level down, its stylesheet links use ../styles/..., which the verifier checks by resolving every href on disk.

Gotchas

  • Placeholders are filled after content is inserted, so content may use site URLs but must not contain accidental {{SOMETHING}} text.
  • A site that brings its own full page shell (the migrated games site) sets "mode": "static". The shared builder is bypassed and its own build copies src/ to dist/.
  • A site with its own framework (the Astro research site) sets "mode": "astro" and uses its own build.js; it still imports the shared header, footer, tokens and analytics.
  • dist/ is generated. Never edit it by hand.