menu: allow empty ul

This simplyfies code, as of now it is only necessary to tag the ul with
classes and let the CSS do all the heavy lifting.

Care was taken, to not mess up layout when a ul ends up with all
its li hidden.
This commit is contained in:
Sören Weber 2021-08-26 22:19:52 +02:00
parent 43e600bc0c
commit c81bf82ced
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589
2 changed files with 32 additions and 27 deletions

View file

@ -108,40 +108,43 @@
{{if and .IsSection (or (and (not .Params.hidden) (ne .Title "")) $.showhidden )}} {{if and .IsSection (or (and (not .Params.hidden) (ne .Title "")) $.showhidden )}}
{{safeHTML .Params.head}} {{safeHTML .Params.head}}
{{ $currentAlwaysopen := .Params.alwaysopen | default $alwaysopen }} {{ $currentAlwaysopen := .Params.alwaysopen | default $alwaysopen }}
<li data-nav-id="{{.RelPermalink}}" title="{{.Title}}" class="dd-item{{if eq .File.UniqueID $currentFileUniqueID}} active{{else if .IsAncestor $currentNode }} parent{{else if $currentAlwaysopen}} parent{{end}}"> <li data-nav-id="{{.RelPermalink}}" title="{{.Title}}" class="dd-item
{{if eq .File.UniqueID $currentFileUniqueID}} active{{end}}
{{if .IsAncestor $currentNode }} parent{{end}}
{{if $currentAlwaysopen}} alwaysopen{{end}}
">
<a href="{{.RelPermalink}}"> <a href="{{.RelPermalink}}">
{{ partial "menu-pre.html" . }}{{or .Params.menuTitle .LinkTitle .Title}}{{ partial "menu-post.html" . }} {{ partial "menu-pre.html" . }}{{or .Params.menuTitle .LinkTitle .Title}}{{ partial "menu-post.html" . }}
{{ if $showvisitedlinks}}<i class="fas fa-check read-icon"></i>{{end}} {{ if $showvisitedlinks}}<i class="fas fa-check read-icon"></i>{{end}}
</a> </a>
{{ $numberOfPages := (add (len (where (where .Pages "Params.hidden" "ne" true ) "Title" "ne" "" )) (len (where (where .Sections "Params.hidden" "ne" true ) "Title" "ne" "" )) ) }} <ul>
{{ if ne $numberOfPages 0 }} {{ $currentNode.Scratch.Set "pages" .Pages }}
<ul> {{ if .Sections}}
{{ $currentNode.Scratch.Set "pages" .Pages }} {{ $currentNode.Scratch.Set "pages" (.Pages | union .Sections) }}
{{ if .Sections}} {{end}}
{{ $currentNode.Scratch.Set "pages" (.Pages | union .Sections) }} {{ $pages := ($currentNode.Scratch.Get "pages") }}
{{end}}
{{ $pages := ($currentNode.Scratch.Get "pages") }}
{{if eq .Site.Params.ordersectionsby "title"}} {{if eq .Site.Params.ordersectionsby "title"}}
{{ range $pages.ByTitle }} {{ range $pages.ByTitle }}
{{ if and (or (.Params.hidden) (eq .Title "")) (not $.showhidden) }}
{{else}}
{{ template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" true}}
{{end}}
{{ end }}
{{else}}
{{ range $pages.ByWeight }}
{{ if and (or (.Params.hidden) (eq .Title "")) (not $.showhidden) }} {{ if and (or (.Params.hidden) (eq .Title "")) (not $.showhidden) }}
{{else}} {{else}}
{{ template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" true}} {{ template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" true}}
{{end}} {{end}}
{{ end }} {{ end }}
{{end}} {{else}}
</ul> {{ range $pages.ByWeight }}
{{ end }} {{ if and (or (.Params.hidden) (eq .Title "")) (not $.showhidden) }}
{{else}}
{{ template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" true}}
{{end}}
{{ end }}
{{end}}
</ul>
</li> </li>
{{else if and (not .Params.hidden) (ne .Title "") }} {{else if and (not .Params.hidden) (ne .Title "") }}
<li data-nav-id="{{.RelPermalink}}" title="{{.Title}}" class="dd-item{{if eq .File.UniqueID $currentFileUniqueID}} active{{end}}"> <li data-nav-id="{{.RelPermalink}}" title="{{.Title}}" class="dd-item
{{if eq .File.UniqueID $currentFileUniqueID}} active{{end}}
">
<a href="{{ .RelPermalink}}"> <a href="{{ .RelPermalink}}">
{{ partial "menu-pre.html" . }}{{or .Params.menuTitle .LinkTitle .Title}}{{ partial "menu-post.html" . }} {{ partial "menu-pre.html" . }}{{or .Params.menuTitle .LinkTitle .Title}}{{ partial "menu-post.html" . }}
{{ if $showvisitedlinks}}<i class="fas fa-check read-icon"></i>{{end}} {{ if $showvisitedlinks}}<i class="fas fa-check read-icon"></i>{{end}}

View file

@ -212,12 +212,14 @@ textarea:focus, input[type="email"]:focus, input[type="number"]:focus, input[typ
} }
#sidebar ul.topics ul { #sidebar ul.topics ul {
display: none; display: none;
}
#sidebar ul.topics > li > ul > li:last-child {
padding-bottom: 1rem; padding-bottom: 1rem;
} }
#sidebar ul.topics ul ul { #sidebar ul.topics ul ul {
padding-bottom: 0; padding-bottom: 0;
} }
#sidebar ul.topics li.parent > ul, #sidebar ul.topics li.active > ul { #sidebar ul.topics li.parent > ul, #sidebar ul.topics li.active > ul, #sidebar ul.topics li.alwaysopen > ul {
display: block; display: block;
} }
#sidebar ul.topics > li > a { #sidebar ul.topics > li > a {
@ -231,7 +233,7 @@ textarea:focus, input[type="email"]:focus, input[type="number"]:focus, input[typ
#sidebar ul.topics > li > a .fa { #sidebar ul.topics > li > a .fa {
margin-top: 9px; margin-top: 9px;
} }
#sidebar ul.topics > li.parent, #sidebar ul.topics > li.active { #sidebar ul.topics > li.parent {
background: #251f29; background: #251f29;
margin-left: -1rem; margin-left: -1rem;
margin-right: -1rem; margin-right: -1rem;