From 650e1e497330cf4845673eca5e5b0affc86db2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Tue, 30 May 2023 18:52:04 +0200 Subject: [PATCH] Fix the sidebar in recent versions of Hugo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kévin Commaille --- assets/scss/custom.scss | 20 ++++-- config.toml | 2 + layouts/partials/sidebar-tree.html | 101 +++++++++++++++++------------ 3 files changed, 76 insertions(+), 47 deletions(-) diff --git a/assets/scss/custom.scss b/assets/scss/custom.scss index 9d748bd2..277b5a42 100644 --- a/assets/scss/custom.scss +++ b/assets/scss/custom.scss @@ -68,9 +68,8 @@ Custom SCSS for the Matrix spec margin-top: 1rem; } - &>.td-sidebar-nav__section > li > a.td-sidebar-link { - font-weight: $font-weight-bold; - font-size: 1.3rem; + .td-sidebar-nav__section .ul-1 ul { + padding-left: 0; } /* This is to make the width of the items that have sub-items (like room versions) @@ -79,12 +78,20 @@ Custom SCSS for the Matrix spec padding-right: 0 !important; } - a.indent-1 { + .ul-1 > li > a { padding-left: 1rem !important; } - a.indent-2 { - padding-left: 2rem; + .ul-2 > li > a { + padding-left: 2rem !important; + } + + a.td-sidebar-link.tree-root { + color: $gray-800; + font-weight: $font-weight-bold; + font-size: 1.3rem; + margin-bottom: 0; + border-bottom: none; } a, a.td-sidebar-link { @@ -103,7 +110,6 @@ Custom SCSS for the Matrix spec &.active, &active:hover { background-color: $secondary-background; - font-weight: $font-weight-normal; } } } diff --git a/config.toml b/config.toml index 00757bd5..3cf2a50b 100644 --- a/config.toml +++ b/config.toml @@ -62,6 +62,8 @@ current_version_url = "https://spec.matrix.org/latest" footer_about_disable = false # Collapse HTTP API and event
elements rendered_data_collapsed = false +# Hide the search entry in the sidebar +sidebar_search_disable = true [params.links] # End user relevant links. These will show up on left side of footer and in the community page if you have one. diff --git a/layouts/partials/sidebar-tree.html b/layouts/partials/sidebar-tree.html index 3589868e..03ecacf0 100644 --- a/layouts/partials/sidebar-tree.html +++ b/layouts/partials/sidebar-tree.html @@ -4,58 +4,79 @@ modifications: * include `div#toc` for the ToC - * start the sidebar at the root (homepage) since for us that is the Matrix - overview page */}} {{/* We cache this partial for bigger sites and set the active class client side. */}} -{{ $shouldDelayActive := ge (len .Site.Pages) 2000 }} +{{ $sidebarCacheLimit := cond (isset .Site.Params.ui "sidebar_cache_limit") .Site.Params.ui.sidebar_cache_limit 2000 -}} +{{ $shouldDelayActive := ge (len .Site.Pages) $sidebarCacheLimit -}}
+ {{ if not .Site.Params.ui.sidebar_search_disable -}} + + {{ else -}}
-
- -{{ define "section-tree-nav-section" }} - {{ $s := .section }} - {{ $p := .page }} - {{ $shouldDelayActive := .delayActive }} - {{ $indent := .indent }} - {{ $active := eq $p.RelPermalink $s.RelPermalink }} - {{ $show := or ($p.IsAncestor $s) ($p.IsDescendant $s) }} - {{ $sid := $s.RelPermalink | anchorize }} -
    -
  • - {{ $s.LinkTitle }} - {{ $pages := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true }} - {{ $pages := $pages | first 50 }} - {{ if gt (len $pages) 0 }} -
      - {{ range $pages }} - {{ if .IsPage }} - {{ $mid := printf "m-%s" (.RelPermalink | anchorize) }} - {{ $active := eq . $p }} -
    • - {{ .LinkTitle }} -
    • - {{ else }} - {{ $indent := add $indent 1 }} - {{ template "section-tree-nav-section" (dict "page" $p "section" . "indent" $indent) }} - {{ end }} - {{ end }} -
    - {{ end }} -
  • -
-{{ end }} +{{ define "section-tree-nav-section" -}} +{{ $s := .section -}} +{{ $p := .page -}} +{{ $shouldDelayActive := .shouldDelayActive -}} +{{ $sidebarMenuTruncate := .sidebarMenuTruncate -}} +{{ $treeRoot := cond (eq .ulNr 0) true false -}} +{{ $ulNr := .ulNr -}} +{{ $ulShow := .ulShow -}} +{{ $active := and (not $shouldDelayActive) (eq $s $p) -}} +{{ $activePath := and (not $shouldDelayActive) (or (eq $p $s) ($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)) (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 -}} +{{ $pages := $pages_tmp | first $sidebarMenuTruncate -}} +{{ $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 -}} +
  • + {{ if (and $p.Site.Params.ui.sidebar_menu_foldable (ge $ulNr 1)) -}} + + + {{ else -}} + {{ with $s.Params.Icon}}{{ end }}{{ $s.LinkTitle }} + {{- end }} + {{- if $withChild }} + {{- $ulNr := add $ulNr 1 }} +
      + {{ range $pages -}} + {{ if (not (and (eq $s $p.Site.Home) (eq .Params.toc_root true))) -}} + {{ template "section-tree-nav-section" (dict "page" $p "section" . "shouldDelayActive" $shouldDelayActive "sidebarMenuTruncate" $sidebarMenuTruncate "ulNr" $ulNr "ulShow" $ulShow) }} + {{- end }} + {{- end }} +
    + {{- end }} +
  • +{{- end }}