From 4d016545dbd73c42470261b2144c88ae5db0cac9 Mon Sep 17 00:00:00 2001 From: Tim Bannister Date: Sat, 2 Nov 2024 17:58:12 +0000 Subject: [PATCH] Adapt sidebar navigation for newer Docsy --- hugo.toml | 2 + layouts/partials/sidebar-tree.html | 76 ++++++++++++------------------ 2 files changed, 31 insertions(+), 47 deletions(-) diff --git a/hugo.toml b/hugo.toml index 13ba477cc9..b0fde0b773 100644 --- a/hugo.toml +++ b/hugo.toml @@ -218,6 +218,8 @@ url = "https://v1-27.docs.kubernetes.io" [params.ui] # Enable to show the side bar menu in its compact state. sidebar_menu_compact = false +# Show this many levels in compact mode +ul_show = 3 # Show expand/collapse icon for sidebar sections. sidebar_menu_foldable = true # https://github.com/gohugoio/hugo/issues/8918#issuecomment-903314696 diff --git a/layouts/partials/sidebar-tree.html b/layouts/partials/sidebar-tree.html index f8ce9b468e..ae6f622df6 100644 --- a/layouts/partials/sidebar-tree.html +++ b/layouts/partials/sidebar-tree.html @@ -1,36 +1,35 @@ -{{/* We cache this partial for bigger sites and set the active class client side. */}} -{{ $sidebarCacheLimit := cond (isset .Site.Params.ui "sidebar_cache_limit") .Site.Params.ui.sidebar_cache_limit 2000 -}} -{{ $shouldDelayActive := ge (len .Site.Pages) $sidebarCacheLimit -}} +{{/* Always cache this partial; set the active class client side. */}} +{{ $shouldDelayActive := true }}
{{ if not .Site.Params.ui.sidebar_search_disable -}} {{ else -}}
{{ end -}}
@@ -42,9 +41,10 @@ {{ $treeRoot := cond (eq .ulNr 0) true false -}} {{ $ulNr := .ulNr -}} {{ $ulShow := .ulShow -}} + {{ $currentLang := .currentLang -}} {{ $active := and (not $shouldDelayActive) (eq $s $p) -}} {{ $activePath := and (not $shouldDelayActive) ($p.IsDescendant $s) -}} - {{ $show := cond (or (lt $ulNr $ulShow) $activePath (and (not $shouldDelayActive) (eq $s.Parent $p.Parent)) (and (not $shouldDelayActive) (eq $s.Parent $p)) (and (not $shouldDelayActive) ($p.IsDescendant $s.Parent))) true false -}} + {{ $show := cond (or (lt $ulNr $ulShow) $activePath (and (not $shouldDelayActive) (eq $s.Parent $p.Parent)) (and (not $shouldDelayActive) (eq $s.Parent $p)) (not $p.Site.Params.ui.sidebar_menu_compact) (and (not $shouldDelayActive) ($p.IsDescendant $s.Parent))) true false -}} {{ $mid := printf "m-%s" ($s.RelPermalink | anchorize) -}} {{ $pages_tmp := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true -}} {{/* We get untranslated subpages below to make sure we build all levels of the sidenav in localizationed docs sets */}} @@ -60,44 +60,26 @@ {{ $withChild := gt (len $pages) 0 -}} {{ $manualLink := cond (isset $s.Params "manuallink") $s.Params.manualLink ( cond (isset $s.Params "manuallinkrelref") (relref $s $s.Params.manualLinkRelref) $s.RelPermalink) -}} {{ $manualLinkTitle := cond (isset $s.Params "manuallinktitle") $s.Params.manualLinkTitle $s.Title -}} - + {{ $isForeignLanguage := (ne (string $s.Lang) ($.currentLang)) -}}
  • {{ if (and $p.Site.Params.ui.sidebar_menu_foldable (ge $ulNr 1)) -}} - - + + {{ else -}} - {{ if not $treeRoot }} - {{ with $s.Params.Icon}}{{ end }}{{ $s.LinkTitle }} - {{ end -}} - {{ end -}} - {{ if $withChild -}} - {{ $ulNr := add $ulNr 1 -}} - + {{ if not $treeRoot }} + {{ with $s.Params.Icon}}{{ end }}{{ $s.LinkTitle }}{{ if $isForeignLanguage }} ({{ $s.Lang | upper }}){{ end -}} + {{- end }} + {{- end }} + {{- if $withChild }} + {{- $ulNr := add $ulNr 1 }} + {{- end }}
  • -{{- end }} +{{- end }} \ No newline at end of file