use details to only open current section in docs menu

This commit is contained in:
a 2022-12-11 18:29:48 -06:00
parent 89c0a4dca9
commit 317e9651c9

View file

@ -9,53 +9,44 @@
<a id="menu" href="#top">Skip menu</a> <a id="menu" href="#top">Skip menu</a>
{{ $currentPage := . }} {{ $currentPage := . }}
{{ range .Site.Menus.docs }} {{ range .Site.Menus.docs }}
{{ if .HasChildren}} {{ $active := or ($currentPage.IsMenuCurrent "docs" .) (eq $currentPage.Section .Identifier)}}
<li {{ if .HasChildren }}
class='section-title{{ if or ($currentPage.IsMenuCurrent "docs" .) (eq $currentPage.Section .Identifier) }} active{{ end }}'> <details
<a href="{{ .URL | relLangURL }}"> class='section-title
{{- if $active }} active{{ end -}}
'
{{- if $active }} open{{ end -}}>
<summary href="{{ .URL | relLangURL }}">
{{ .Pre }} {{ .Pre }}
<span>{{ .Name }}</span> <span>{{ .Name }}</span>
{{ .Post }} {{ .Post }}
</a> </summary>
<ul class="sub-menu"> <ul class="sub-menu">
{{ range .Children }} {{ range .Children }}
{{ if .HasChildren}} {{ if .HasChildren}}
<li
class='{{ if or ($currentPage.IsMenuCurrent "docs" .) (eq $currentPage.Section .Identifier) }} active{{ end }}'>
<a href="{{ .URL | relLangURL }}">
{{ .Pre }}
<span>{{ .Name }}</span>
{{ .Post }}
</a>
<ul class="sub-menu">
{{ range .Children }}
<li <li
class='{{ if or ($currentPage.IsMenuCurrent "docs" .) (eq $currentPage.Section .Identifier) }}active{{ end }}'> class='{{- if $active }} active{{ end -}}'>
<a href="{{ .URL | relLangURL }}"> <a href="{{ .URL | relLangURL }}">
{{ .Pre }} {{ .Pre }}
<span>{{ .Name }}</span> <span>{{ .Name }}</span>
{{ .Post }} {{ .Post }}
</a> </a>
</li> <ul class="sub-menu">
{{ end }} {{ range .Children }}
</ul> <li
</li> class='{{- if $active }} active{{ end -}}'>
<a href="{{ .URL | relLangURL }}">
{{ .Pre }}
<span>{{ .Name }}</span>
{{ .Post }}
</a>
</li>
{{ end }}
</ul>
</details>
{{ else }} {{ else }}
<li <li
class='{{ if or ($currentPage.IsMenuCurrent "docs" .) (eq $currentPage.Section .Identifier) }}active{{ end }}'> class='{{- if $active }} active{{ end -}}'>
<a href="{{ .URL | relLangURL }}">
{{ .Pre }}
<span>{{ .Name }}</span>
{{ .Post }}
</a>
</li>
{{ end }}
{{ end }}
</ul>
</li>
{{ else }}
<li
class='{{ if or ($currentPage.IsMenuCurrent "docs" .) (eq $currentPage.Section .Identifier) }}active{{ end }}'>
<a href="{{ .URL | relLangURL }}"> <a href="{{ .URL | relLangURL }}">
{{ .Pre }} {{ .Pre }}
<span>{{ .Name }}</span> <span>{{ .Name }}</span>
@ -65,5 +56,18 @@
{{ end }} {{ end }}
{{ end }} {{ end }}
</ul> </ul>
</li>
{{ else }}
<li
class='{{- if $active }} active{{ end -}}'>
<a href="{{ .URL | relLangURL }}">
{{ .Pre }}
<span>{{ .Name }}</span>
{{ .Post }}
</a>
</li>
{{ end }}
{{ end }}
</ul>
</div> </div>
</nav> </nav>