Skip to main content

render_site_nav

Function render_site_nav 

Source
pub fn render_site_nav(
    nav: &SiteNavigation,
    site_title: &str,
    root_prefix: &str,
) -> String
Expand description

Render the site navigation: the mobile bar, then the sidebar.

site_title names the masthead — the link home at the top of the sidebar, which is where a site’s name goes on every other site. The front page leaves the tree for it: when the tree’s one root is the front page (index.html, the destination this crate gives every root), the list starts at its children, so an entry sits at the depth it has rather than one deeper. A rootless forest lists as it is, under a masthead that still links to index.html, which is where a supplied or synthesized front page lands.

A node with children is a disclosure — <details> around a <summary> holding the link — written open on the current page’s ancestors and on the current page’s own node, and closed everywhere else. The whole tree is still in the HTML: crawlable, printable, searchable with the browser’s find, and correct with scripting off. No state is stored anywhere; which sections are open is a function of which page this is.

The link and the disclosure are separate targets: the <a> is the summary’s content, so activating it navigates, and the rest of the summary — the chevron the stylesheet draws — toggles.