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,19 +9,23 @@
<a id="menu" href="#top">Skip menu</a>
{{ $currentPage := . }}
{{ range .Site.Menus.docs }}
{{ $active := or ($currentPage.IsMenuCurrent "docs" .) (eq $currentPage.Section .Identifier)}}
{{ if .HasChildren }}
<li
class='section-title{{ if or ($currentPage.IsMenuCurrent "docs" .) (eq $currentPage.Section .Identifier) }} active{{ end }}'>
<a href="{{ .URL | relLangURL }}">
<details
class='section-title
{{- if $active }} active{{ end -}}
'
{{- if $active }} open{{ end -}}>
<summary href="{{ .URL | relLangURL }}">
{{ .Pre }}
<span>{{ .Name }}</span>
{{ .Post }}
</a>
</summary>
<ul class="sub-menu">
{{ range .Children }}
{{ if .HasChildren}}
<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>
@ -30,7 +34,7 @@
<ul class="sub-menu">
{{ range .Children }}
<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>
@ -39,10 +43,10 @@
</li>
{{ end }}
</ul>
</li>
</details>
{{ else }}
<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>
@ -55,7 +59,7 @@
</li>
{{ else }}
<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>