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:
2
assets/css/compiled/main.css
generated
2
assets/css/compiled/main.css
generated
File diff suppressed because one or more lines are too long
2
docs/hugo_stats.json
generated
2
docs/hugo_stats.json
generated
@@ -481,6 +481,7 @@
|
||||
"hx:ltr:pl-5",
|
||||
"hx:ltr:pl-6",
|
||||
"hx:ltr:pl-8",
|
||||
"hx:ltr:pr-0",
|
||||
"hx:ltr:pr-1",
|
||||
"hx:ltr:pr-2",
|
||||
"hx:ltr:pr-4",
|
||||
@@ -639,6 +640,7 @@
|
||||
"hx:rtl:mr-1",
|
||||
"hx:rtl:mr-3",
|
||||
"hx:rtl:mr-auto",
|
||||
"hx:rtl:pl-0",
|
||||
"hx:rtl:pl-1",
|
||||
"hx:rtl:pl-2",
|
||||
"hx:rtl:pl-4",
|
||||
|
||||
@@ -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" -}}
|
||||
|
||||
Reference in New Issue
Block a user