On this page

How the theme is built

The theme is a set of Jinja templates and one stylesheet, with a little Python between Sphinx and the templates. npm run build compiles the stylesheet from assets/theme.css, and compiles assets/content.css a second time on its own as the page-body stylesheet, which reads none of the other files in assets/. This page says where each part lives, for a change that has to find it.

The page context

Sphinx calls add_page_context in sphinx_daisyui.events for every page it writes. It reads the theme’s options with ThemeOptions from sphinx_daisyui.options and gives the templates one dictionary, daisy, which is the only place a template reads an option from. The JSON and pickle builders write the context out instead of rendering a template, so add_page_context gives them no daisy dictionary. check_layout stops the build when the layout option is not a layout code, which LayoutCode in sphinx_daisyui.layout reads.

The site navigation

SiteNavigation in sphinx_daisyui.navigation reads the site’s toctrees once for a page as docutils nodes, with Sphinx’s global_toctree_for_doc. It marks the nodes for the stylesheet, adds a toggle beside every entry with pages under it, and renders them once with the builder. Nothing is parsed back from HTML.

The HTML writer’s link takes no aria-current, so the link to the current page is swapped for a CurrentLink node, which the theme registers with visit_current_link and depart_current_link to write it.

Fixed text the Python writes, such as a toggle’s name, is marked for translation with translate, Sphinx’s translator for the sphinx message domain that the templates use too.

On this page

PageContents in sphinx_daisyui.navigation reads the page’s headings from document_toc, which Sphinx builds from the page’s table of contents, as docutils nodes. It drops the page’s own title, marks each list with daisy-toc-list, each link with daisy-toc-link and each list deeper than show_toc_level with daisy-toc-deep, and renders them once. add_page_context gives the templates the result as daisy.page_toc, with daisy.page_toc_count and daisy.show_toc_level. static/scripts/page-toc.js marks the heading being read with aria-current="location" and its entries with daisy-toc-on-path, which shows the deeper headings of that section.

is_index_page in sphinx_daisyui.events tells the search page, the domain indexes and the general indexes from other pages by the template Sphinx renders them with. They have no headings of their own, so add_page_context gives them an empty secondary sidebar and no contents.

Icons

Icons in sphinx_daisyui.icons reads the bundled icons.json, and ICONS is the one instance the templates and the Python share.

Theme names

themes.json lists every theme daisyUI ships, in daisyUI’s own order, which is the list a site’s theme_picker = true offers. scripts/themes.mjs writes it from daisyUI’s themeOrder.js, and npm run build rewrites it when the list changes, so a daisyUI upgrade needs no edit by hand.

Modes and themes

Modes in sphinx_daisyui.modes reads light_theme, dark_theme, default_mode and theme_picker into daisy.modes. check_modes warns once at the start of the build when default_mode is not auto, light or dark. The site’s values reach the page on the <script> element that loads static/scripts/mode.js, which sets the attributes on <html> before the page is drawn and holds the one function that applies a reader’s choice. static/scripts/theme-menu.js wires the theme menu to it.

Versions

VersionSwitcher in sphinx_daisyui.versions reads the switcher option and show_version_warning_banner into daisy.switcher. check_switcher, connected to the end of the build, reads the site’s switcher.json once and warns when it cannot be used. static/scripts/versions.js lists the versions in the page and fills the banner.