{# SPDX-FileCopyrightText: 2026 PythonWoods <dev@pythonwoods.dev> #}
{# SPDX-License-Identifier: Apache-2.0 #}
{#
  path.html — Breadcrumb override.
  - Adds the current page as the last crumb (plain text, accented).
  - Section crumbs that have no dedicated index page (they point to their
    first child) are rendered as plain text instead of misleading links.
#}
{% import "partials/path-item.html" as item with context %}
{% if page.meta and page.meta.hide %}
  {% set hidden = "hidden" if "path" in page.meta.hide %}
{% endif %}
{% set depth = page.ancestors | length %}
{% if nav.homepage %}
  {% set depth = depth + 1 %}
{% endif %}
{% if depth > 0 %}
  <nav class="md-path" aria-label="{{ lang.t('nav') }}" {{ hidden }}>
    <ol class="md-path__list">
      {% if nav.homepage %}
        {{ item.render(nav.homepage) }}
      {% endif %}
      {% for nav_item in page.ancestors | reverse %}
        {# Section groups (no direct index) resolve to their first child.
           If that child is the current page, render as plain text — not a
           self-referential link that appears to do nothing. #}
        {% if nav_item.children %}
          {% set first = nav_item.children | first %}
          {% if first.url == page.url %}
            <li class="md-path__item md-path__item--section">
              <span class="md-ellipsis">{{ nav_item.title }}</span>
            </li>
          {% else %}
            {{ item.render(nav_item) }}
          {% endif %}
        {% else %}
          {{ item.render(nav_item) }}
        {% endif %}
      {% endfor %}
      {# Current page — no link, accent colour #}
      <li class="md-path__item md-path__item--current">
        <span class="md-ellipsis">{{ page.title }}</span>
      </li>
    </ol>
  </nav>
{% endif %}
