Skip to content

Add a JS plugin loading mechanism and decompose scripts.html - #2788

Merged
chalin merged 12 commits into
docsy:mainfrom
chalin:chalin-m24-plugins-substrate-2026-0902
Sep 2, 2026
Merged

chalin merged 12 commits into
docsy:mainfrom
chalin:chalin-m24-plugins-substrate-2026-0902

Conversation

@chalin

@chalin chalin commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator
  • Contributes to Add a JS plugin loading mechanism #2789.
  • Decomposes _partials/scripts.html into per-feature sub-partials behind a small dispatcher:
    • Default rendered output is unchanged: a golden net pins the rendered script region and byte-pins every locally built script in its fixtures
    • Each sub-partial becomes independently overridable, and the dispatcher is the seam the plugin loop lands in
    • The inline algolia/head and algolia/scripts defines become real partials, making the documented override paths work; Add a JS plugin loading mechanism #2789 tracks the upgrade note for the removed template names
  • Adds the plugin loop: params.docsy.plugins entries emit scripts from assets/js/plugins/ (union-FS shadowing applies), each built with js.Build and fingerprinted in every environment:
    • Options travel as params -> @params; pageGate generalizes the mermaid/katex .Page.Store gating so a plugin ships only on pages that use its feature
    • Companions, emitted before the script tag: a scripts/plugins/NAME.html partial (invoked with the page and the registry entry) and a scss/plugins/NAME.scss stylesheet through the SCSS pipeline
    • Malformed registry shapes warn instead of erroring, so sites already carrying a params.docsy value are untouched
  • Tests are red-first throughout: loop-contract pins, a zero-layout-override acceptance test, an offline dispatch net for the legacy Store-flag partials, and a browser runtime net with a built-in red-proof against silent no-ops
  • Scope: existing loading mechanisms are untouched; converting built-in integrations onto the loop is follow-up work.
  • Preview:

- Pins the rendered post-footer script region and the js/main.js bundle,
  under two fixture configs (theme defaults; every offline-safe loading
  mechanism lit), ahead of the scripts.html decomposition
- Whitespace- and fingerprint-name-insensitive comparison, so only real
  behavior changes go red
- Splits the loading mechanisms into
  scripts/{main-bundle,plantuml-deflate,code-copy,algolia,tabpane-persist}.html,
  leaving scripts.html a ~20-line dispatcher; no behavior change
  (scripts-golden net unchanged)
- Each sub-partial is now independently overridable, and the dispatcher is
  the seam the plugin loop lands in
- Emits registered plugins from assets/js/plugins/ (theme, project, or
  module mounts; union-FS shadowing applies), each built individually with
  js.Build; options travel as params -> @params
- Registry entries carry enable/defer/pageGate; pageGate generalizes the
  mermaid/katex .Page.Store gating so a plugin ships only on pages using
  its feature
- Companion conventions: scripts/plugins/NAME.html renders after the
  plugin's script tag; assets/scss/plugins/NAME.scss ships through the
  SCSS pipeline, linked before it
- Warns (suppressible id) when a registered plugin has no matching asset
- Acceptance test: a fixture project adds a plugin with zero layout
  overrides
- A fixture plugin must actually execute (window flag + DOM mutation +
  @params delivery) in a real browser: static markup checks can bless a
  broken runtime
- Red-proof built in: a deliberately broken plugin's error must be the
  collector's exact tally, so an empty tally can't false-green
@chalin chalin added this to the 0.18.0 milestone Sep 2, 2026
@chalin chalin mentioned this pull request Sep 2, 2026
4 of 6 tasks
- Emits plugin companions (partial, stylesheet) before the script tag, so
  a synchronous plugin script can rely on companion-provided libs and
  markup
- Compares the main.js bundle golden byte-exactly (normalize collapsed
  whitespace inside JS strings, a false-green path) and lights Algolia in
  the featureful fixture (a changed mechanism the net did not cover;
  output verified byte-identical to main's rendered define)
- search.md: points the Algolia override at the new scripts/algolia.html
  partial (the documented algolia/scripts.html path never worked: the
  inline define always won)
- Rephrases absence assert messages in the repo's affirmative style
All fixes pinned red-first (6 new tests red on the prior loop):

- Guards the registry read: a scalar params.docsy no longer breaks the
  build (the namespace is new; unopted sites must be untouched), a
  non-list plugins value warns, a bare-name entry is shorthand, and a
  nameless entry is skipped with a warning
- Fingerprints plugin builds in every environment: distinct builds of one
  source (per-language options, duplicate registrations) published to the
  same dev path, last write winning site-wide
- Warns about a missing plugin asset independently of its pageGate, so a
  config typo surfaces even when no page sets the flag
- Adds a dispatch net for the .Page.Store-gated legacy partials (mermaid,
  katex) via offline marker overrides, and pins stylesheet-before-script
  companion order
- Extracts head.html's algolia/head define into a real partial, making
  search.md's documented override path work (an empty site copy was
  silently ignored: the inline define always won)
- Wires update:scripts-goldens into update:goldens, so a full golden
  refresh can't silently skip the scripts net
- Strips integrity attributes in the golden region comparison (content-
  addressed, same as fingerprint names; bundle bytes and CDN versions are
  pinned elsewhere) and corrects the normalize rationale
- Prunes cSpell ignores to words the project dictionary lacks, and trims
  stray indentation from emitted plugin markup
- Coerces plugin names to strings throughout the loop: YAML auto-types
  `name: 2048` to an int, which broke the asset lookup and garbled the
  missing-asset warning (pinned red-first)
- Invokes companion partials with (dict "Page" ... "Plugin" ...): entry
  options were unreachable from companions, and the context shape freezes
  at release (pinned red-first)
- Replaces the fixed-path zero-output asserts, which could never fail
  against fingerprinted output, with published-dir inspection
- Narrows the golden integrity-strip to sha256 fingerprints, so the
  region goldens keep pinning CDN SRI hashes
- Replaces literal em-dashes in test comments with plainer marks
- Prunes test headers and comments that restated the loop contract or the
  adjacent code; the contract's home is the plugin loop's header
- Points the golden refresh cue at the npm script
- Golden test header defers fixture and comparison detail to the lib that
  owns it, dropping a stale byte-identical claim and spike-era naming
- Byte-pins click-to-copy alongside main.js: the region comparison strips
  fingerprint names and sha256 integrity, so a content change to any
  locally built script could pass unpinned (reviewer-reproduced); the
  byte-golden set now derives from the page markup, with a stale-golden
  guard for configs a script is absent from
- Warns on falsy scalar params.docsy.plugins values too: `plugins: false`
  slipped past the `with`-guard silently (pinned by a new test)
- Stores region goldens in canonical form (no trailing whitespace, final
  newline): the comparison is whitespace-insensitive, so the stored bytes
  only tripped `git diff --check`
@chalin
chalin merged commit 21ea675 into docsy:main Sep 2, 2026
18 checks passed
chalin added a commit to chalin/docsy that referenced this pull request Sep 4, 2026
The four queued 0.18 lines (docsy#2780, docsy#2787, docsy#2788, docsy#2790) stay queued for a
CL-touching PR of their own; the release-prep coverage ledger keeps them as
todo.
chalin added a commit to chalin/docsy that referenced this pull request Oct 7, 2026
0.17's guide listed two override paths the theme never read (Algolia was inline
defines); docsy#2788 made them partials, one at a new path. The gate names the
readers who followed the docs; the details row records the path move.
chalin added a commit to chalin/docsy that referenced this pull request Oct 7, 2026
…follows

The speaker-page URL no longer resolves; the Sched session page does. The
cache also gains the docsy#2788 entry the changelog's Algolia line needs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant