fix(navbar): align mobile sidebar ordering and labels with menu.main (#883)

* fix(navbar): navbar on small screen now follow menu.main from hugo.yaml

* fix(navbar): align mobile sidebar with menu.main order and labels

* refactor(sidebar): simplify mobile menu item selection logic

* fix(sidebar): avoid empty nested containers in mobile nav tree

* fix(sidebar): align nested chevrons with top-level items

* chore(css): update compiled CSS

---------

Co-authored-by: Xin <5097752+imfing@users.noreply.github.com>
Co-authored-by: Xin <xin@imfing.com>
This commit is contained in:
Antonin P
2026-02-20 00:34:06 +01:00
committed by GitHub
parent 9b2809eb24
commit 55659bb9c1
3 changed files with 28 additions and 6 deletions

View File

@@ -77,11 +77,26 @@
{{- $pageURL := .page.RelPermalink -}}
{{- $level := .level -}}
{{- $toc := .toc | default false -}}
{{- $useMainMenu := and (eq $level 0) $toc -}}
{{- $menuNamesByPath := dict -}}
{{- with $items := union .context.RegularPages .context.Sections -}}
{{- $items = where $items "Params.sidebar.exclude" "!=" true -}}
{{- $items := where (union .context.RegularPages .context.Sections) "Params.sidebar.exclude" "!=" true -}}
{{- if $useMainMenu -}}
{{- $items = slice -}}
{{- range $menuItem := site.Menus.main -}}
{{- with $menuItem.Page -}}
{{- if ne .Params.sidebar.exclude true -}}
{{- $items = $items | append . -}}
{{- $menuNamesByPath = merge $menuNamesByPath (dict .Path (or (T $menuItem.Identifier) $menuItem.Name)) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if gt (len $items) 0 -}}
{{- if eq $level 0 -}}
{{- range $items.ByWeight }}
{{- $topLevelItems := cond $useMainMenu $items $items.ByWeight -}}
{{- range $topLevelItems }}
{{- if .Params.sidebar.separator -}}
<li class="[word-break:break-word] hx:mt-5 hx:mb-2 hx:px-2 hx:py-1.5 hx:text-sm hx:font-semibold hx:text-gray-900 hx:first:mt-0 hx:dark:text-gray-100">
<span class="hx:cursor-default">{{ partial "utils/title" . }}</span>
@@ -91,6 +106,11 @@
{{- $shouldOpen := or (.Params.sidebar.open) (.IsAncestor $page) $active | default true }}
<li class="{{ if $shouldOpen }}open{{ end }}">
{{- $linkTitle := partial "utils/title" . -}}
{{- if $useMainMenu -}}
{{- with index $menuNamesByPath .Path -}}
{{- $linkTitle = . -}}
{{- end -}}
{{- end -}}
{{- 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" . -}}
@@ -100,7 +120,7 @@
{{- end -}}
{{- end -}}
{{- else -}}
<div class="hextra-sidebar-children hx:ltr:pr-1 hx:rtl:pl-1 hx:overflow-hidden">
<div class="hextra-sidebar-children hx:ltr:pr-0 hx:rtl:pl-0 hx:overflow-hidden">
<ul class='hx:relative hx:flex hx:flex-col hx:gap-1 hx:before:absolute hx:before:inset-y-1 hx:before:w-px hx:before:bg-gray-200 hx:before:content-[""] hx:ltr:ml-3 hx:ltr:pl-3 hx:ltr:before:left-0 hx:rtl:mr-3 hx:rtl:pr-3 hx:rtl:before:right-0 hx:dark:before:bg-neutral-800'>
{{- range $items.ByWeight }}
{{- $active := eq $pageURL .RelPermalink -}}
@@ -117,7 +137,7 @@
</ul>
</div>
{{- end -}}
{{- end }}
{{- end -}}
{{- end -}}
{{- define "sidebar-toc" -}}