6.1 The docs site
The documentation site at docs.tempofrc.com is a static Astro build in
website/. It publishes two books from one build, which are the user docs
written for robot teams and this Contributing book rendered from
docs/contributing/*.md. Read this chapter before changing navigation,
components, search, or the site gates. The docs style guide
covers writing and visual rules.
Stack and layout
The site runs Astro 5 with the Starlight 0.30 integration
(website/package.json). Starlight supplies routing, the content schema and
the page shell, but almost every visible part of it is replaced. The
components map in website/astro.config.mjs overrides Head, PageFrame,
Header, Sidebar, TwoColumnContent, PageSidebar, PageTitle,
MarkdownContent, ContentPanel, Footer, ThemeSelect, ThemeProvider and
MobileMenuToggle with files in website/src/components/. Starlight’s own
Pagefind search and Expressive Code are turned off (pagefind: false,
expressiveCode: false), and the site has its own search index and highlights
code with Shiki at build time.
Use Node 24 (website/.node-version). From website/:
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm ci
npm run dev # development server with reload
npm run check # the full source and build gate
npm run test:ui # browser tests against dist/| Path | Contains |
|---|---|
website/src/content/docs/ | User pages, MDX, one file per route |
docs/contributing/ | Contributor guides, plain Markdown, read in place |
website/src/nav.ts | Both books: chapters, groups, page order, numbering |
website/src/components/ | Starlight overrides and the MDX components pages use |
website/src/pages/ | Routes outside the docs collection: the Contributing book, the two search indexes, 404, favicon |
website/src/scripts/docs.ts | The one deferred script every page loads |
website/src/scripts/search.ts | The search palette, loaded on first open |
website/src/styles/custom.css | All layout, typography and color |
website/plugins/ | Rehype transforms and the Shiki theme |
website/scripts/ | Gates: API names, glyphs, C++ snippets, links, content, budgets, browser tests |
website/public/ | Files served as is: _headers, robots.txt, teaching-field downloads |
Content collections
website/src/content.config.ts defines two collections. docs is
Starlight’s loader over website/src/content/docs/, with three extra
frontmatter fields: pageLayout (article, guide or overview),
compatibility (badges under the title, split on sentence ends by
PageTitle.astro) and langFilter (false shows every language’s
single-language blocks on that page). contributing is a glob loader over
../docs/contributing/*.md, with the file name as the entry id and an empty
schema, so the guides carry no frontmatter.
The Contributing route, website/src/pages/contributing/[...slug].astro,
publishes only the files contributingPages lists in nav.ts. It takes the page
title from the file’s first # line and passes the H2 and H3 headings to the
right rail. A file listed in nav.ts but missing from disk fails the build
with a message naming the file. website/scripts/content.test.mjs fails when a
tracked docs/contributing/*.md file has no entry, or an entry names an
untracked file.
The two books
website/src/nav.ts is the single source for navigation. sections is the
user book and contributingSections is the Contributing book, and both are arrays of
DocSection chapters holding pages and groups of pages. numberBook numbers
each book’s pages through their chapter (2.3), with group labels inside a
chapter leaving the count alone and a single chapter numbered as one row.
bookFor(path) returns the chapters, numbered pages and home page of the book
a path belongs to. Sidebar.astro, PageTitle.astro and Footer.astro all
call it, so the sidebar, the title number, the breadcrumbs and the
previous/next links follow the right book without a second code path.
| User docs | Contributing book | |
|---|---|---|
| Routes | /, /getting-started/, /concepts/, /robot-code/, /reference/, /gui/, /troubleshooting/, /error-messages/ | /contributing/ and /contributing/<slug>/ |
| Source | MDX in website/src/content/docs/ | Markdown in docs/contributing/ |
| Chapters | sections | contributingSections |
| Home row | Introduction (/) | Contributing home (docs/contributing/README.md) |
| Header wordmark | ”Tempo”, gold mark, “Docs" | "Tempo”, red mark, “Contributing” |
| Header right | Language, WPILib year, Contributing link, GitHub | User docs link, GitHub |
| Last sidebar row | Tempo Contributing | Back to the user docs |
| Search index | /search-index.json | /contributing/search-index.json |
| Accent | --accent gold | --contrib red, set by .shell-contrib |
inContributing(path) decides which book a page is in. PageFrame.astro adds
the shell-contrib class to the page shell on Contributing pages, and
custom.css redefines --accent, --accent-hi and --tempo-icon-accent
under that class, so every accent on those pages (links, chapter numbers, the
current row, the wordmark) turns red without separate rules. The Tempo mark
is TempoIcon.astro, which is the three bars of assets/brand/tempoIcon.svg
with the background tile removed, filled with
var(--tempo-icon-accent, #ffc544). Setting that variable on any ancestor
recolors the mark, and that is how the header’s Contributing link and the
sidebar’s crossing row show a red mark inside the gold user docs.
A contributor guide’s slug is its file name in lowercase kebab case
(contributingSlug), so simValidation.md -> /contributing/sim-validation/ and
README.md -> /contributing/. Renaming a file moves its URL, so add a
redirect in astro.config.mjs when that happens. Every guide also answers at
its /internals/<slug>/ address through redirects generated from
contributingPages in the same file.
Adding a contributor guide
- Create
docs/contributing/<name>.mdstarting with a# Titleline. - Add
{ file: '<name>', label: '<sidebar label>' }tocontributingPagesinwebsite/src/nav.ts. - Add
'<name>'to a chapter incontributingSections, at the place it should be read. A['Group label', [...]]entry makes a labeled group. git addthe file, because the content test only sees tracked files.- Run
npm run check.
Links between guides are relative Markdown links ([FFI contract](ffi-contract.md#known-hazards)).
website/plugins/rehypeInternals.mjs rewrites them at build time. A link to a
listed guide becomes its /contributing/ route, a link to a page under
website/src/content/docs/ becomes that page’s route, and a link to any other
repository file becomes plain text, because the site does not serve the source
tree. The same plugin drops the file’s H1, since PageTitle.astro renders the
title with its book number. With the rewrite, links work both on GitHub and on
the site.
Adding a user page
Create the MDX file under website/src/content/docs/ in the folder of its
chapter (getting-started/, concepts/, robot-code/, reference/ or
gui/, and a single-page chapter sits at the top level), add one entry for it to
a chapter in sections, and keep the existing URLs. A moved or merged page
gets a line in the redirects map of astro.config.mjs, pointing at the
current page and never at another redirect. The build writes the same map to
dist/_redirects, which Cloudflare Pages serves as 301s that keep the URL
fragment, and Astro’s own redirect pages are the fallback. The content test
every public page has exactly one navigation entry fails on an orphan page,
a duplicate entry, or an entry with no page.
Rendering pipeline
Markdown and MDX pass through two rehype plugins and a Shiki transformer, all
configured in astro.config.mjs:
| Step | File | Effect |
|---|---|---|
rehypeDocs | website/plugins/rehypeDocs.mjs | Splits a step number out of ## 1. Title and ## 2b. Title headings, ends every H2, H3 and H4 with a section link (.h-anchor), wraps tables in a scrolling frame, marks Language table rows with data-lang-only, and records headings inside langs components as langHeadings |
rehypeInternals | website/plugins/rehypeInternals.mjs | Contributor guides only: drops the H1 and rewrites relative links |
| Shiki | website/plugins/codeBlocks.mjs | tempoTheme colors tokens at build time and codeFrame wraps each block in the frame with its language label and Copy button |
Pages ship no highlighter and no web font, and text uses the system UI and
monospace stacks declared at the top of custom.css.
Page shell and scripts
PageFrame.astro renders a fixed 46px header, the fixed sidebar and the
article column, and the page body scrolls. TwoColumnContent.astro adds the zoom
control and the right rail, which PageSidebar.astro fills with “On this
page” and, on pages in an ordered group, the group’s steps.
The site has one deferred module script, website/src/scripts/docs.ts, plus
an inline script in Head.astro. The inline script reads the stored language,
WPILib year, app and zoom from localStorage (tempo-docs-lang,
tempo-docs-year, tempo-docs-app, tempo-docs-zoom) and sets them as
data-* attributes on <html> before first paint. CSS draws every tab group
and language-only block from those attributes, so the right pane is visible
before any script runs. docs.ts changes the attributes on request and runs
the sidebar filter, copy buttons, scroll-spy, the phone menu, keyboard keys
(Ctrl K or Cmd K for search, / for the filter, left and right arrows for the
previous and next page), the sidebar’s saved scroll position
(sessionStorage key tempo-docs-sidebar), the recently read list, and a
hover prefetch for browsers without speculation rules.
A section link puts its heading’s address in the address bar with
history.replaceState and copies it to the clipboard, then shows “Link
copied” beside the icon for a moment. The link has no text, and custom.css
draws its icon with a mask, so a heading’s text in “On this page” and the
search index is unchanged and each link adds under 100 bytes of HTML. The icon
shows on hover and keyboard focus, and always under (hover: none). When the
page opens on a fragment whose heading sits in a hidden tab pane or
language-only block, docs.ts selects the tabs and language that show it.
While Python is the selected language, the year tabs and the header’s year
select read “RobotPy 2026” and “RobotPy 2027”. The tabs carry both names and
CSS shows one, and the select’s option text is set by its inline script before
first paint and by docs.ts on a change. Head.astro also emits
speculation rules that prerender sidebar and previous/next links on hover.
The site has one palette. ThemeProvider.astro sets data-theme="dark"
before first paint and custom.css declares the same tokens for both theme
attributes, so a light system preference renders the same page.
MDX components
User pages import these from website/src/components/, and contributor guides
are plain Markdown and use none of them.
| Component | Use |
|---|---|
CodeTabs | Equivalent Java, Python and C++ blocks or prose, following the site-wide language |
YearTabs | Content that differs between WPILib 2026 and 2027 |
AppTabs | Content that differs between the desktop app and the browser editor |
LangOnly | Content for some languages only; its headings leave “On this page” with it |
IfItFails, Fail | The “If it fails…” list: symptom, console message, fix |
SymptomIndex | The Troubleshooting page’s index built from its own headings, each with its section’s first console line. A section whose symptom prints nothing carries {/* index: no console line */} |
Callout | An aside with a semantic kind label |
GuideStep, GuideFigure | Walkthrough steps and sized screenshots |
ReleaseLink | A release address from website/src/installLinks.ts, or pending text while it is empty |
HomeHero, FindTopic | The Introduction page |
Search
Search is a palette (SearchPalette.astro) whose code and data load on first
use. docs.ts imports search.ts when the palette opens (or when the pointer
first enters the search button), and search.ts fetches one JSON index. The
index is chosen by the page’s path, so a /contributing/ page fetches
/contributing/search-index.json and any other page fetches /search-index.json.
The two books never mix in one result list, so a team searching for a method
name does not land in a build guide, and a maintainer searching for a source
file stays in the guides.
Both indexes are arrays of [kind, title, trail, href, detail, extra]
tuples built at build time.
website/src/pages/search-index.json.tsreads the MDX sources and emitspage,heading,apianderrorentries. API entries come from the first column of tables underreference/whose header isMethod,Factory,JavaorFactories, with a snake_case alias in the extra text. Console messages come fromMessagetable columns,message="..."attributes,textorconsolefences, and inline code shaped like a sentence or a[Tempo]line.website/src/pages/contributing/search-index.json.tsemits apageentry per guide and aheadingentry per H2 and H3. Each heading’s extra text holds the inline code under it (file paths, function names, commands), capped at 600 characters, so a search forplan_rejoinorTEMPO_REGEN_TRACESfinds the section that cites it.
search.ts scores titles first (exact, prefix, substring), then the extra
text, then multi-word overlap, and groups results by kind. The sample queries
and starting pages shown with an empty query differ per book (TRIES and
START).
/llms.txt lists each user page under its chapter with its description, in
the llmstxt.org format, and /llms-full.txt holds every user page as one
Markdown file. website/src/flatDocs.ts builds both from the MDX sources and
nav.ts, and leaves the Contributing book out.
Gates
npm run check (website/scripts/check.mjs) runs the source checks in
parallel with astro build, then the checks that read dist/. Any failure
fails the gate, and each part also runs alone.
| Check | Script | Fails on |
|---|---|---|
check:api | scripts/check-api.mjs | A member call, type, import, include or tempo:: name in a java, python or cpp fence that the binding sources do not define. Names only, not signatures |
check:glyphs | scripts/check-glyphs.mjs | En or em dashes, ellipses, curly quotes or box-drawing characters in user-page prose |
check:cpp-snippets | scripts/check-cpp-snippets.mjs | A cpp fence that is not a snippet tests/robot/cpp_docs/src/test/cpp/sim/DocsSnippetsTest.cpp compiles, or a marked snippet missing from its page |
test:content | scripts/content.test.mjs, scripts/checks.test.mjs | Navigation contracts (one entry per page, one row per guide), teaching-example contracts, and the checkers’ own tests |
check:links | scripts/check-links.mjs | A built link to a missing page, asset or fragment, or a relative href |
test:budget | scripts/budget.test.mjs | Page weight over budget (below) |
test:text | scripts/docs-text.test.mjs | A sidebar page missing from /llms.txt or /llms-full.txt, MDX left in the text, a lost code fence, or a link to a missing page or fragment |
npm run test:ui (scripts/ui.test.mjs) serves dist/ on a temporary port
and drives Chromium through Playwright. It covers the header and both
wordmarks, the numbered books, the crossing links between them, the
/internals/ redirects, search in each book, language and year tabs, keyboard
navigation, the phone menu, and a layout check that every built page fits at
390, 800, 1024, 1280 and 1920px with unique ids and exactly one current book
row. TEMPO_DOCS_CHROMIUM_PATH selects an installed Chromium instead of
Playwright’s download.
Page-weight budget
scripts/budget.test.mjs holds these limits on every built page (bytes before
compression):
| Budget | Limit |
|---|---|
| Linked CSS per page | 48 KB |
| Module script per page | 14 KB |
| HTML per page | 220 KB |
search-index.json | 220 KB |
It also fails when a page inlines a module script, references the search chunk
or a search index before the palette opens, loads or preloads a font file,
or shows a PNG screenshot without a WebP <picture> source, width, height and
lazy loading (the Introduction’s hero alone loads eagerly at high priority).
The largest contributor guides are the pages closest to the HTML limit, because
the Contributing sidebar and a long guide add up on one page. Split a guide
that grows past it instead of raising the limit.
Deployment
The docs’ Python blocks (all but the WPILib 2027 panes and two skipped
placeholders) run in the robot simulation
(python/robot_sim/test_docs_snippets.py), part of the
Python gate.
The site deploys as static files from website/dist/ on Cloudflare Pages.
website/public/_headers caches the content-hashed /_astro/* files for a
year and leaves pages and search indexes on the default revalidation, so a
deploy shows at once.