{{- /* This template recursively renders the sidebar navigation, grouping pages by `Params.sidebar.groups`. Highlights: - Supports hierarchical navigation with collapsible sections (`renderList` template). - Dynamically applies current page highlighting and expanded states. - Handles external links via `Params.sidebar.goto` in `renderSingle`. - Requires `Params.sitemap` and `Params.sidebar` for filtering and behavior. */ -}} {{ define "renderChildren" }} {{- $section := .section }} {{- $revealHidden := .revealHidden }} {{- $sourcePages := $section.Pages }} {{- if $section.Params.sidebar.reverse }} {{ $sourcePages = $sourcePages.Reverse }} {{- end }} {{- $pages := slice }} {{- range $sourcePages }} {{- $isActive := or (eq page .) (page.IsDescendant .) }} {{- if and (or (not $section.Params.sidebar.activeChildrenOnly) $isActive) (or (ne .Params.sitemap false) $isActive $revealHidden) }} {{- $pages = $pages | append . }} {{- end }} {{- end }} {{- $ungrouped := where $pages "Params.sidebar.group" "==" nil }} {{- if $section.Params.sidebar.activeChildrenOnly }} {{- $ungrouped = $pages }} {{- end }} {{- range $ungrouped }} {{- if and .IsSection (not .Params.apiID) }} {{- template "renderList" (dict "section" . "revealHidden" $revealHidden) }} {{- else }} {{- template "renderSingle" . }} {{- end }} {{- end }} {{- $groups := $section.Params.sidebar.groups }} {{- if $section.Params.sidebar.activeChildrenOnly }} {{- $groups = slice }} {{- end }} {{- range $groups }} {{- end }} {{ end }} {{/* Recursive template for sidebar items */}} {{ define "renderList" }} {{- $section := .section }} {{- $isCurrent := eq page $section }} {{- $expanded := or $isCurrent (page.IsDescendant $section) }} {{- $revealHidden := or .revealHidden (and (eq $section.Params.sitemap false) $expanded) }}
  • {{- if $section.Permalink }} {{/* If the link is not empty, use it */}} {{ template "renderTitle" $section }} {{- else }} {{/* Otherwise, just expand the section */}} {{- end }}
    {{/* Only show expand group button if section has children */}} {{- $children := slice }} {{- range $section.Pages }} {{- $isActive := or (eq page .) (page.IsDescendant .) }} {{- if and (or (not $section.Params.sidebar.activeChildrenOnly) $isActive) (or (ne .Params.sitemap false) $isActive $revealHidden) }} {{- $children = $children | append . }} {{- end }} {{- end }} {{- $hasChildren := gt (len $children) 0 }} {{- if $hasChildren }} {{- end }}
  • {{ end }} {{ define "renderSingle" }} {{- if .Params.sidebar.goto }}
  • {{ template "renderTitle" . }}
  • {{- else }} {{ $isCurrent := eq page . }}
  • {{ template "renderTitle" . }}
  • {{- end }} {{ end }} {{ define "renderTitle" }} {{ .LinkTitle }} {{- with .Params.sidebar.badge }} {{- partial "components/badge.html" (dict "color" .color "content" .text) }} {{- end }} {{ end }}