Fix the sidebar in recent versions of Hugo

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
Kévin Commaille 2023-05-30 18:52:04 +02:00
parent 48459dee9b
commit 650e1e4973
No known key found for this signature in database
GPG key ID: 29A48C1F03620416
3 changed files with 76 additions and 47 deletions

View file

@ -68,9 +68,8 @@ Custom SCSS for the Matrix spec
margin-top: 1rem; margin-top: 1rem;
} }
&>.td-sidebar-nav__section > li > a.td-sidebar-link { .td-sidebar-nav__section .ul-1 ul {
font-weight: $font-weight-bold; padding-left: 0;
font-size: 1.3rem;
} }
/* This is to make the width of the items that have sub-items (like room versions) /* 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; padding-right: 0 !important;
} }
a.indent-1 { .ul-1 > li > a {
padding-left: 1rem !important; padding-left: 1rem !important;
} }
a.indent-2 { .ul-2 > li > a {
padding-left: 2rem; 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 { a, a.td-sidebar-link {
@ -103,7 +110,6 @@ Custom SCSS for the Matrix spec
&.active, &active:hover { &.active, &active:hover {
background-color: $secondary-background; background-color: $secondary-background;
font-weight: $font-weight-normal;
} }
} }
} }

View file

@ -62,6 +62,8 @@ current_version_url = "https://spec.matrix.org/latest"
footer_about_disable = false footer_about_disable = false
# Collapse HTTP API and event <details> elements # Collapse HTTP API and event <details> elements
rendered_data_collapsed = false rendered_data_collapsed = false
# Hide the search entry in the sidebar
sidebar_search_disable = true
[params.links] [params.links]
# End user relevant links. These will show up on left side of footer and in the community page if you have one. # End user relevant links. These will show up on left side of footer and in the community page if you have one.

View file

@ -4,58 +4,79 @@
modifications: modifications:
* include `div#toc` for the ToC * 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. */}} {{/* 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 -}}
<div id="td-sidebar-menu" class="td-sidebar__inner{{ if $shouldDelayActive }} d-none{{ end }}"> <div id="td-sidebar-menu" class="td-sidebar__inner{{ if $shouldDelayActive }} d-none{{ end }}">
{{ if not .Site.Params.ui.sidebar_search_disable -}}
<form class="td-sidebar__search d-flex align-items-center">
{{ partial "search-input.html" . }}
<button class="btn btn-link td-sidebar__toggle d-md-none p-0 ml-3 fas fa-bars" type="button" data-toggle="collapse" data-target="#td-section-nav" aria-controls="td-section-nav" aria-expanded="false" aria-label="Toggle section navigation">
</button>
</form>
{{ else -}}
<div id="content-mobile"> <div id="content-mobile">
<form class="td-sidebar__search d-flex align-items-center"> <form class="td-sidebar__search d-flex align-items-center">
{{ partial "search-input.html" . }} {{ partial "search-input.html" . }}
<button class="btn btn-link td-sidebar__toggle d-md-none p-0 ml-3 fas fa-bars" type="button" data-toggle="collapse" data-target="#td-section-nav" aria-controls="td-docs-nav" aria-expanded="false" aria-label="Toggle section navigation"> <button class="btn btn-link td-sidebar__toggle d-md-none p-0 ml-3 fas fa-bars" type="button" data-toggle="collapse" data-target="#td-section-nav" aria-controls="td-section-nav" aria-expanded="false" aria-label="Toggle section navigation">
</button> </button>
</form> </form>
</div> </div>
<div id="content-desktop"></div> <div id="content-desktop"></div>
<nav class="collapse td-sidebar-nav" id="td-section-nav"> {{ end -}}
{{ template "section-tree-nav-section" (dict "page" . "section" .Site.Home.CurrentSection "delayActive" $shouldDelayActive "indent" 0) }} <nav class="collapse td-sidebar-nav{{ if .Site.Params.ui.sidebar_menu_foldable }} foldable-nav{{ end }}" id="td-section-nav">
{{ if (gt (len .Site.Home.Translations) 0) -}}
<div class="nav-item dropdown d-block d-lg-none">
{{ partial "navbar-lang-selector.html" . }}
</div>
{{ end -}}
{{ $navRoot := cond (and (ne .Params.toc_root true) (eq .Site.Home.Type "docs")) .Site.Home .FirstSection -}}
{{ $ulNr := 0 -}}
{{ $ulShow := cond (isset .Site.Params.ui "ul_show") .Site.Params.ui.ul_show 1 -}}
{{ $sidebarMenuTruncate := cond (isset .Site.Params.ui "sidebar_menu_truncate") .Site.Params.ui.sidebar_menu_truncate 50 -}}
<ul class="td-sidebar-nav__section pr-md-3 ul-{{ $ulNr }}">
{{ template "section-tree-nav-section" (dict "page" . "section" $navRoot "shouldDelayActive" $shouldDelayActive "sidebarMenuTruncate" $sidebarMenuTruncate "ulNr" $ulNr "ulShow" (add $ulShow 1)) }}
</ul>
<hr/> <hr/>
<div id = "toc"></div> <div id="toc"></div>
</nav> </nav>
</div> </div>
{{ define "section-tree-nav-section" -}}
{{ define "section-tree-nav-section" }} {{ $s := .section -}}
{{ $s := .section }} {{ $p := .page -}}
{{ $p := .page }} {{ $shouldDelayActive := .shouldDelayActive -}}
{{ $shouldDelayActive := .delayActive }} {{ $sidebarMenuTruncate := .sidebarMenuTruncate -}}
{{ $indent := .indent }} {{ $treeRoot := cond (eq .ulNr 0) true false -}}
{{ $active := eq $p.RelPermalink $s.RelPermalink }} {{ $ulNr := .ulNr -}}
{{ $show := or ($p.IsAncestor $s) ($p.IsDescendant $s) }} {{ $ulShow := .ulShow -}}
{{ $sid := $s.RelPermalink | anchorize }} {{ $active := and (not $shouldDelayActive) (eq $s $p) -}}
<ul class="td-sidebar-nav__section pr-md-3"> {{ $activePath := and (not $shouldDelayActive) (or (eq $p $s) ($p.IsDescendant $s)) -}}
<li class="td-sidebar-nav__section-title"> {{ $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 -}}
<a href="{{ $s.RelPermalink }}" class="align-left pl-0 pr-2{{ if not $show }} collapsed{{ end }}{{ if $active}} active{{ end }} td-sidebar-link td-sidebar-link__section indent-{{$indent}}">{{ $s.LinkTitle }}</a> {{ $mid := printf "m-%s" ($s.RelPermalink | anchorize) -}}
{{ $pages := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true }} {{ $pages_tmp := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true -}}
{{ $pages := $pages | first 50 }} {{ $pages := $pages_tmp | first $sidebarMenuTruncate -}}
{{ if gt (len $pages) 0 }} {{ $withChild := gt (len $pages) 0 -}}
<ul> {{ $manualLink := cond (isset $s.Params "manuallink") $s.Params.manualLink ( cond (isset $s.Params "manuallinkrelref") (relref $s $s.Params.manualLinkRelref) $s.RelPermalink) -}}
{{ range $pages }} {{ $manualLinkTitle := cond (isset $s.Params "manuallinktitle") $s.Params.manualLinkTitle $s.Title -}}
{{ if .IsPage }} <li class="td-sidebar-nav__section-title td-sidebar-nav__section{{ if $withChild }} with-child{{ else }} without-child{{ end }}{{ if $activePath }} active-path{{ end }}{{ if (not (or $show $p.Site.Params.ui.sidebar_menu_foldable )) }} collapse{{ end }}" id="{{ $mid }}-li">
{{ $mid := printf "m-%s" (.RelPermalink | anchorize) }} {{ if (and $p.Site.Params.ui.sidebar_menu_foldable (ge $ulNr 1)) -}}
{{ $active := eq . $p }} <input type="checkbox" id="{{ $mid }}-check"{{ if $activePath}} checked{{ end }}/>
<li class="collapse {{ if $show }}show{{ end }}" id="{{ $sid }}"> <label for="{{ $mid }}-check"><a href="{{ $manualLink }}"{{ if ne $s.LinkTitle $manualLinkTitle }} title="{{ $manualLinkTitle }}"{{ end }}{{ with $s.Params.manualLinkTarget }} target="{{ . }}"{{ if eq . "_blank" }} rel="noopener"{{ end }}{{ end }} class="align-left pl-0 {{ if $active}} active{{ end }} td-sidebar-link{{ if $s.IsPage }} td-sidebar-link__page{{ else }} td-sidebar-link__section{{ end }}{{ if $treeRoot }} tree-root{{ end }}" id="{{ $mid }}">{{ with $s.Params.Icon}}<i class="{{ . }}"></i>{{ end }}<span class="{{ if $active }}td-sidebar-nav-active-item{{ end }}">{{ $s.LinkTitle }}</span></a></label>
<a class="td-sidebar-link td-sidebar-link__page {{ if and (not $shouldDelayActive) $active }} active{{ end }} indent-{{add $indent 1}}" id="{{ $mid }}" href="{{ .RelPermalink }}">{{ .LinkTitle }}</a> {{ else -}}
</li> <a href="{{ $manualLink }}"{{ if ne $s.LinkTitle $manualLinkTitle }} title="{{ $manualLinkTitle }}"{{ end }}{{ with $s.Params.manualLinkTarget }} target="{{ . }}"{{ if eq . "_blank" }} rel="noopener"{{ end }}{{ end }} class="align-left pl-0{{ if $active}} active{{ end }} td-sidebar-link{{ if $s.IsPage }} td-sidebar-link__page{{ else }} td-sidebar-link__section{{ end }}{{ if $treeRoot }} tree-root{{ end }}" id="{{ $mid }}">{{ with $s.Params.Icon}}<i class="{{ . }}"></i>{{ end }}<span class="{{ if $active }}td-sidebar-nav-active-item{{ end }}">{{ $s.LinkTitle }}</span></a>
{{ else }} {{- end }}
{{ $indent := add $indent 1 }} {{- if $withChild }}
{{ template "section-tree-nav-section" (dict "page" $p "section" . "indent" $indent) }} {{- $ulNr := add $ulNr 1 }}
{{ end }} <ul class="ul-{{ $ulNr }}{{ if (gt $ulNr 1)}} foldable{{end}}">
{{ end }} {{ range $pages -}}
</ul> {{ if (not (and (eq $s $p.Site.Home) (eq .Params.toc_root true))) -}}
{{ end }} {{ template "section-tree-nav-section" (dict "page" $p "section" . "shouldDelayActive" $shouldDelayActive "sidebarMenuTruncate" $sidebarMenuTruncate "ulNr" $ulNr "ulShow" $ulShow) }}
</li> {{- end }}
</ul> {{- end }}
{{ end }} </ul>
{{- end }}
</li>
{{- end }}