hugo-theme-learn
hugo-theme-learn copied to clipboard
Menu: only expand active hierarchy (fixes #195)
Pull request @robhoes is on older version of theme and required some work. Reviewed those edits, then used master to redo the edits to prepare this pull request.
Is there a specific reason why this hasn't been merged yet?
@oldenboom the following diff fixes the conflicts in menu.html:
diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html
index 5583eda..c023003 100644
--- a/layouts/partials/menu.html
+++ b/layouts/partials/menu.html
@@ -99,18 +99,25 @@
{{with .sect}}
{{if and .IsSection (or (not .Params.hidden) $.showhidden)}}
{{safeHTML .Params.head}}
+ {{ $isParent := or (.IsAncestor $currentNode) (.Params.alwaysopen) }}
+ {{ $numberOfPages := (add (len .Pages) (len .Sections)) }}
<li data-nav-id="{{.RelPermalink}}" title="{{.Title}}" class="dd-item
- {{if .IsAncestor $currentNode }}parent{{end}}
+ {{if $isParent }}parent{{end}}
{{if eq .File.UniqueID $currentFileUniqueID}}active{{end}}
- {{if .Params.alwaysopen}}parent{{end}}
">
<a href="{{.RelPermalink}}">
{{safeHTML .Params.Pre}}{{or .Params.menuTitle .LinkTitle .Title}}{{safeHTML .Params.Post}}
+ {{ if and (ne $numberOfPages 0) (ne .Parent .Site.Home) }}
+ {{if $isParent }}
+ <i class="fas fa-caret-down"></i>
+ {{ else }}
+ <i class="fas fa-caret-right"></i>
+ {{ end }}
+ {{ end }}
{{ if $showvisitedlinks}}
- <i class="fas fa-check read-icon"></i>
+ <i class="fas fa-check"></i>
{{ end }}
</a>
- {{ $numberOfPages := (add (len .Pages) (len .Sections)) }}
{{ if ne $numberOfPages 0 }}
<ul>
{{ $currentNode.Scratch.Set "pages" .Pages }}