{{- $context := .context -}} {{- $disableSidebar := .disableSidebar | default false -}} {{- $displayPlaceholder := .displayPlaceholder | default false -}} {{- $navRoot := cond (eq site.Home.Type "docs") site.Home $context.FirstSection -}} {{- $pageURL := $context.RelPermalink -}} {{- if .context.Params.sidebar.hide -}} {{- $disableSidebar = true -}} {{- $displayPlaceholder = false -}} {{- end -}} {{- $sidebarClass := "hx:md:sticky" -}} {{- if $disableSidebar -}} {{- if $displayPlaceholder -}} {{- $sidebarClass = "hx:md:hidden hx:xl:block" -}} {{- else -}} {{- $sidebarClass = "hx:md:hidden" -}} {{- end -}} {{- end -}} {{- define "sidebar-main" -}} {{ template "sidebar-tree" (dict "context" .context "level" 0 "page" .page "pageURL" .pageURL "toc" (.toc | default false)) }} {{- end -}} {{- define "sidebar-tree" -}} {{- if ge .level 4 -}} {{- return -}} {{- end -}} {{- $context := .context -}} {{- $page := .page }} {{- $pageURL := .page.RelPermalink -}} {{- $level := .level -}} {{- $toc := .toc | default false -}} {{- $useMainMenu := and (eq $level 0) $toc -}} {{- $mainMenuEntries := slice -}} {{- $items := where (union .context.RegularPages .context.Sections) "Params.sidebar.exclude" "!=" true -}} {{- if $useMainMenu -}} {{- range $menuItem := site.Menus.main -}} {{- $menuType := $menuItem.Params.type | default "" -}} {{- $isIconOnly := and $menuItem.Params.icon (ne $menuType "link") -}} {{- /* Keep only navigation links in the mobile sidebar. */ -}} {{- if or (eq $menuType "search") (eq $menuType "theme-toggle") (eq $menuType "language-switch") $isIconOnly -}} {{- continue -}} {{- end -}} {{- $menuTitle := or (T $menuItem.Identifier) $menuItem.Name -}} {{- /* Dropdown parents mirror navbar behavior: render a labeled group of child links. */ -}} {{- if $menuItem.HasChildren -}} {{- $childEntries := slice -}} {{- range $childItem := $menuItem.Children -}} {{- $childType := $childItem.Params.type | default "" -}} {{- $childIsIconOnly := and $childItem.Params.icon (ne $childType "link") -}} {{- if or (eq $childType "search") (eq $childType "theme-toggle") (eq $childType "language-switch") $childIsIconOnly -}} {{- continue -}} {{- end -}} {{- $childTitle := or (T $childItem.Identifier) $childItem.Name -}} {{- $childPage := $childItem.Page -}} {{- with $childItem.PageRef -}} {{- with $page.Site.GetPage . -}} {{- $childPage = . -}} {{- end -}} {{- end -}} {{- with $childPage -}} {{- if ne .Params.sidebar.exclude true -}} {{- $childEntries = $childEntries | append (dict "title" $childTitle "link" .RelPermalink) -}} {{- end -}} {{- continue -}} {{- end -}} {{- $childLink := $childItem.URL -}} {{- with $childItem.PageRef -}} {{- if hasPrefix . "/" -}} {{- $childLink = relLangURL (strings.TrimPrefix "/" .) -}} {{- end -}} {{- end -}} {{- if $childLink -}} {{- $childEntries = $childEntries | append (dict "title" $childTitle "link" $childLink) -}} {{- end -}} {{- end -}} {{- if gt (len $childEntries) 0 -}} {{- $mainMenuEntries = $mainMenuEntries | append (dict "type" "group" "title" $menuTitle "children" $childEntries) -}} {{- end -}} {{- continue -}} {{- end -}} {{- /* Normalize page-backed entries so we keep nested tree behavior. */ -}} {{- $menuPage := $menuItem.Page -}} {{- with $menuItem.PageRef -}} {{- with $page.Site.GetPage . -}} {{- $menuPage = . -}} {{- end -}} {{- end -}} {{- with $menuPage -}} {{- if ne .Params.sidebar.exclude true -}} {{- $mainMenuEntries = $mainMenuEntries | append (dict "type" "page" "item" . "title" $menuTitle) -}} {{- end -}} {{- continue -}} {{- end -}} {{- $link := $menuItem.URL -}} {{- with $menuItem.PageRef -}} {{- if hasPrefix . "/" -}} {{- $link = relLangURL (strings.TrimPrefix "/" .) -}} {{- end -}} {{- end -}} {{- if $link -}} {{- $mainMenuEntries = $mainMenuEntries | append (dict "type" "url" "link" $link "title" $menuTitle) -}} {{- end -}} {{- end -}} {{- end -}} {{- $useMainMenuEntries := and $useMainMenu (gt (len $mainMenuEntries) 0) -}} {{- $hasItems := or (gt (len $items) 0) $useMainMenuEntries -}} {{- if $hasItems -}} {{- if eq $level 0 -}} {{- if $useMainMenuEntries -}} {{- /* Mixed list: page entries render trees; url entries render leaf links. */ -}} {{- range $entry := $mainMenuEntries -}} {{- if eq (index $entry "type") "page" -}} {{- $item := index $entry "item" -}} {{- if $item.Params.sidebar.separator -}}
  • {{ index $entry "title" }}
  • {{- else -}} {{- $active := eq (strings.TrimSuffix "/" $pageURL) (strings.TrimSuffix "/" $item.RelPermalink) -}} {{- $shouldOpen := or ($item.Params.sidebar.open) ($item.IsAncestor $page) $active | default true }}
  • {{- template "sidebar-item-link" dict "context" $item "active" $active "open" $shouldOpen "title" (index $entry "title") "link" $item.RelPermalink -}} {{- if and $toc $active (ne $item.Params.toc false) -}} {{- template "sidebar-toc" dict "page" $item -}} {{- end -}} {{- template "sidebar-tree" dict "context" $item "page" $page "pageURL" $pageURL "level" (add $level 1) "toc" $toc -}}
  • {{- end -}} {{- else if eq (index $entry "type") "group" -}}
  • {{- index $entry "title" -}}
  • {{- else -}} {{- $link := index $entry "link" -}} {{- $active := eq (strings.TrimSuffix "/" $pageURL) (strings.TrimSuffix "/" $link) -}}
  • {{ template "sidebar-item-link" dict "active" $active "open" false "title" (index $entry "title") "link" $link }}
  • {{- end -}} {{- end -}} {{- else -}} {{- range $items.ByWeight }} {{- if .Params.sidebar.separator -}}
  • {{ partial "utils/title" . }}
  • {{- else -}} {{- $active := eq $pageURL .RelPermalink -}} {{- $shouldOpen := or (.Params.sidebar.open) (.IsAncestor $page) $active | default true }}
  • {{- $linkTitle := partial "utils/title" . -}} {{- template "sidebar-item-link" dict "context" . "active" $active "open" $shouldOpen "title" $linkTitle "link" .RelPermalink -}} {{- if and $toc $active (ne .Params.toc false) -}} {{- template "sidebar-toc" dict "page" . -}} {{- end -}} {{- template "sidebar-tree" dict "context" . "page" $page "pageURL" $pageURL "level" (add $level 1) "toc" $toc -}}
  • {{- end -}} {{- end -}} {{- end -}} {{- else -}}
    {{- end -}} {{- end -}} {{- end -}} {{- define "sidebar-toc" -}} {{ $page := .page }} {{ with $page.Fragments.Headings }} {{ end }} {{- end -}} {{- define "sidebar-footer" -}} {{- range site.Menus.sidebar -}} {{- $name := or (T .Identifier) .Name -}} {{ if eq .Params.type "separator" }}
  • {{ $name }}
  • {{ else }} {{- $link := .URL -}} {{- with .PageRef -}} {{- if hasPrefix . "/" -}} {{- $link = relLangURL (strings.TrimPrefix "/" .) -}} {{- end -}} {{- end -}}
  • {{ template "sidebar-item-link" dict "active" false "open" false "title" $name "link" $link }}
  • {{ end }} {{- end -}} {{- end -}} {{- define "sidebar-item-link" -}} {{- $external := strings.HasPrefix .link "http" -}} {{- $open := .open | default true -}} {{- $hasChildren := false -}} {{- $linkClass := "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:grow hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] hx:hextra-focus-visible-inset" -}} {{- with .context }}{{ if or .RegularPages .Sections }}{{ $hasChildren = true }}{{ end }}{{ end -}} {{- if $hasChildren -}} {{- $linkClass = printf "%s hx:ltr:pr-8 hx:rtl:pl-8" $linkClass -}} {{- end -}} {{- if .active -}} {{- $linkClass = printf "%s hextra-sidebar-active-item hx:bg-primary-100 hx:font-semibold hx:text-primary-800 hx:contrast-more:border hx:contrast-more:border-primary-500 hx:dark:bg-primary-400/10 hx:dark:text-primary-600 hx:contrast-more:dark:border-primary-500" $linkClass -}} {{- else -}} {{- $linkClass = printf "%s hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50" $linkClass -}} {{- end -}}
    {{- .title -}} {{- if $hasChildren }} {{- end }}
    {{- end -}} {{- define "sidebar-collapsible-button" -}} {{- end -}}