Contribute / Build the docs
Build the docs¶
This page shows how to build these docs, add a page, and add a figure or an interactive explainer. The writing guide sets how the pages read.
Step 1: Install the tools¶
pip install -e . --group docs
--group needs pip 25.1 or later. The API reference imports the package,
so the command installs it too.
Step 2: Build the site¶
sphinx-build -W --keep-going docs docs/_build/html
The command writes the site to docs/_build/html/; open index.html in a
browser. -W turns every warning into an error, a malformed docstring
included, as the CI build does. CI builds the docs for every pull request
and publishes them from main to https://joshspeagle.com/dorothy/.
Where the files are¶
Path |
Holds |
|---|---|
|
The home page and the six section toctrees |
|
The pages of each section |
|
The API pages that autosummary writes at build time; not in git |
|
SVG figures |
|
Logos, the favicon and explainer scripts |
|
The theme: |
|
The bibliography |
|
The Sphinx configuration |
|
Development notes; the build excludes them |
Add a page¶
Write the page in Markdown (MyST) in its section’s folder, for example
docs/guides/my-task.md. Start with a#title and a one- or two-sentence opener.Add the page to its section’s toctree in
docs/index.md, in reading order:```{toctree} :caption: Guides :hidden: guides/train guides/my-task ```Build the site and fix every warning.
The first page of a toctree is the section’s landing page: the top bar links to it.
Add a figure¶
Draw the SVG in
docs/figures/, in the style ofmulti-head.svg. Give it a<title>androle="img".Draw ink in
currentColor. Take role colours from the theme tokens with fallbacks, such asvar(--d-teal, #1D7468).Check the text size of the figure on a 360 px screen. If text renders under 11 px, also draw a narrow variant,
<name>-narrow.svg, 360 units wide.Include it with a caption of one sentence:
::::{container} d-figure ```{raw} html :file: ../figures/name.svg :class: wide-only ``` ```{raw} html :file: ../figures/name-narrow.svg :class: narrow-only ``` :::{container} caption One sentence that states the concept. ::: ::::Without a narrow variant, leave out the second block and the
:class:line. At 600 px and less, the theme showsnarrow-onlyand hideswide-only.
Add an explainer¶
An explainer is an interactive figure on a How it works page. Each explainer
is one script in docs/_static/explainers/, such as precision.js. All
explainers share the styles in explainer.css and the helpers in
explainer.js in the same folder. explainer.js defines one global,
window.dExplainer.
Write the script without external libraries. It finds its container by its id,
d-<name>, and builds the plot, the readout and the controls in it. Build the elements with the helpersel(SVG),htmlandcell(a readout entry).Draw the plot as an SVG with
role="img"and anaria-label. Redraw it in a narrow layout at 600 px and less (matchMedia).Put the readout in an element with
class="d-readout". Do not give itaria-live.Announce changes to screen readers with
status(root). It adds a hidden live region and returnsset(text)andannounce(). Callsetwhen the values change. Callannouncewhen a button is clicked and when the slider sends itschangeevent.Use native controls, which work from the keyboard. Use
<button>elements, witharia-pressedfor a toggle. Where the reader sets a number, use an<input type="range">slider witharia-valuetext.If the explainer draws random numbers, seed them with
mulberry32fromexplainer.js, ascalibration.jsdoes. Then every load is identical.Take colours only from the
--d-*theme tokens, through the classes ofexplainer.css.Load the styles, the container and the scripts with a
{raw} htmlblock on the page:```{raw} html <link rel="stylesheet" href="../_static/explainers/explainer.css"> <div class="d-lab" id="d-name"> <p class="d-lab-h">One sentence that tells the reader what to do.</p> </div> <script src="../_static/explainers/explainer.js" defer></script> <script src="../_static/explainers/name.js" defer></script> ```explainer.jscomes first, so thatwindow.dExplainerexists when the explainer script runs.The paths are relative to the page. A page in a section folder starts them with
../.