On this page
The browser scripts a built page ships, authored as real .js files and embedded rather than written as Go strings, plus the bundle each page assembles.
#internal/js
#internal/js
Package js carries the browser scripts a built page ships and assembles the body bundle each page needs.
The scripts are authored as .js files in this package and embedded, never written as string literals in Go: a script that lives in a Go source file gets no syntax checking, no editor support and no diff a reviewer can read.
#What a page loads
Two scripts sit in the head -- [Head], which applies the stored colour scheme before the first paint, and [Analytics], which is injected only when the project configures it. Everything else is one bundle at the end of the body, assembled by [AssembleBody].
The bundle is not the whole directory. Five blocks are on every page; the rest are included only when the rendered HTML shows the element they drive, which the assembler decides by probing the fragments the page renderer already holds. A page with no code block ships no copy-button handler, and a page with no table of contents ships no scrollspy.
#PageHTML
type PageHTML structPageHTML is the rendered page, in the fragments [AssembleBody] probes to decide which conditional blocks the page needs.
The split is the page renderer's own: the article body, the table of contents, the footer, the template-level extras the wrapper renders around the body (the superseded-version notice and the share control), and the chrome outside the article (the topbar, where the two pickers live).
#Load
func Load(name string) (string, error)Load returns the source of the named script, without its .js extension -- Load("theme-toggle") reads theme-toggle.js. An unknown name is an error.
#Head
func Head() stringHead returns the script every page runs in its head, before the first paint: it applies the colour scheme the visitor last chose and switches scroll behaviour to instant so an initial in-page landing does not animate.
#Analytics
func Analytics() stringAnalytics returns the Google Analytics configuration script, which a page carries only when the project's feedback settings name a measurement id. It reads that id from its own script element's data-ga-id attribute.
#BodyScripts
func BodyScripts(page PageHTML) []stringBodyScripts returns the names of the blocks a page ships, in bundle order.
It is what [AssembleBody] concatenates, exposed on its own because a build stage that reports or checks a page's payload wants the names rather than the bytes.
#AssembleBody
func AssembleBody(page PageHTML) stringAssembleBody returns the body bundle for page: the always-included blocks, then every conditional block whose element the page carries, then the smooth scroll restore, joined by newlines and not yet minified.