Source code for gain.templates.breadcrumb

"""The trail a resource's generated pages show back to the repository.

A resource page and its statistics page carry the same breadcrumb the
index page's hierarchical view draws (gain#1477): the root, one crumb
per id segment, and the page itself last.  Each crumb's address is
decided here rather than in the templates, from the same two facts the
root climb is computed from -- the resource id and where the page sits
inside the resource directory -- so the trail and the climb cannot
drift.  The templates only loop over what this returns.

A crumb into the tree addresses a folder the way the index page
addresses one itself, ``index.html#/<segments>`` (gain#579), so it is a
plain link and the index page does the rest on load.  The root crumb
goes to the tree's root, not to a bare ``index.html``: an empty fragment
means the table view, and the trail is one kind of navigation.
"""
from __future__ import annotations

from dataclasses import dataclass

from gain.templates.static_assets import climb_to_root

#: The root crumb's name, the same words the index page's breadcrumb
#: gives its own root.
ROOT_CRUMB_NAME = "All resources"

#: What follows ``index.html`` to address the tree's root; a folder is
#: this plus its segments, joined by ``/``.
_TREE_HASH = "#/"


[docs] @dataclass(frozen=True) class Crumb: """One step of the trail: its name, and where it leads. ``href`` is ``None`` for the page itself, which is never a link. """ name: str href: str | None