diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index 435dbfa..7c31b38 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -20,6 +20,7 @@ markup: endLevel: 9 params: + geekdocMenuBundle: true geekdocToC: 3 geekdocRepo: https://github.com/thegeeklab/hugo-geekdoc diff --git a/exampleSite/content/toc-tree/level-1/_index.md b/exampleSite/content/toc-tree/level-1/_index.md index acab06a..17df0d2 100644 --- a/exampleSite/content/toc-tree/level-1/_index.md +++ b/exampleSite/content/toc-tree/level-1/_index.md @@ -1,3 +1,7 @@ +--- +geekdocCollapseSection: true +--- + Level 1 diff --git a/exampleSite/data/menu/main.yaml b/exampleSite/data/menu/main.yaml new file mode 100644 index 0000000..1a135aa --- /dev/null +++ b/exampleSite/data/menu/main.yaml @@ -0,0 +1,21 @@ +--- +main: + - name: Level 1 + ref: "/toc-tree/level-1" + sub: + - name: Level 1.1 + ref: "/toc-tree/level-1/level-1-1" + - name: Level 1.2 + ref: "/toc-tree/level-1/level-1-2" + - name: Level 1.3 + ref: "/toc-tree/level-1/level-1-3" + sub: + - name: Level 1.3.1 + ref: "/toc-tree/level-1/level-1-3/level-1-3-1" + - name: Level 2 + ref: "/toc-tree/level-2" + sub: + - name: Level 2.1 + ref: "/toc-tree/level-2/level-2-1" + - name: Level 2.2 + ref: "/toc-tree/level-2/level-2-2" diff --git a/layouts/partials/menu-bundle.html b/layouts/partials/menu-bundle.html index 37a1c08..3062749 100644 --- a/layouts/partials/menu-bundle.html +++ b/layouts/partials/menu-bundle.html @@ -1,6 +1,7 @@ {{ $current := .current }} {{ template "menu-file" dict "sect" .source "current" $current "site" $current.Site }} + {{ define "menu-file" }} {{ $current := .current }} {{ $site := .site }} @@ -17,23 +18,34 @@ {{ $this := $site.GetPage .ref }} {{ $current := $current.Scratch.Get "current" }} {{ $icon := default false .icon }} + {{ $numberOfPages := (add (len $this.Pages) (len $this.Sections)) }} + {{ $isCurrent := eq $current $this }} + {{ $isAncestor := $this.IsAncestor $current }} + {{ $id := substr (sha1 $this.Permalink) 0 8 }} + {{ $hasCollapse := and $this.Params.GeekdocCollapseSection (isset . "sub") }} + {{ if $hasCollapse }} + + + {{ end }} {{ else }} - - {{ .name }} - + {{ .name }} {{ end }} - {{ $sub := default false .sub }} - {{ if $sub }} - {{ template "menu-file" dict "sect" $sub "current" ($current.Scratch.Get "current") "site" ($current.Scratch.Get "site") }} + {{ with .sub }} + {{ template "menu-file" dict "sect" . "current" ($current.Scratch.Get "current") "site" ($current.Scratch.Get "site") }} {{ end }} diff --git a/layouts/partials/menu-filetree.html b/layouts/partials/menu-filetree.html index 10ec7ae..26eddb5 100644 --- a/layouts/partials/menu-filetree.html +++ b/layouts/partials/menu-filetree.html @@ -15,9 +15,10 @@ {{ $isCurrent := eq $current . }} {{ $isAncestor := .IsAncestor $current }} {{ $id := substr (sha1 .Permalink) 0 8 }} + {{ $hasCollapse := and $isParent .Params.GeekdocCollapseSection }}
  • - {{ if and $isParent .Params.GeekdocCollapseSection }} + {{ if $hasCollapse }}