hugo-geekdoc/layouts/partials/menu-bundle.html
Robert Kaussow 5e105c9ff4
feat: auto-load custom svg sprites from assets folder (#79)
BREAKING CHANGE: Build-in icons are prefixed with `gdoc_` now. If you use build-in icons in e.g. menus you have to rename these references!
2021-03-03 21:07:59 +01:00

55 lines
2.3 KiB
HTML

{{ $current := .current }}
{{ template "menu-file" dict "sect" .source "current" $current "site" $current.Site }}
<!-- template -->
{{ define "menu-file" }}
{{ $current := .current }}
{{ $site := .site }}
<ul class="gdoc-nav__list">
{{ range sort (default (seq 0) .sect) "weight" }}
{{ $current.Scratch.Set "current" $current }}
{{ $current.Scratch.Set "site" $site }}
<li>
{{ $ref := default false .ref }}
{{ if $ref}}
{{ $site := $current.Scratch.Get "site" }}
{{ $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 }}
<input type="checkbox" id="{{ printf "navtree-%s" $id }}" class="gdoc-nav__toggle" {{ if or $isCurrent $isAncestor }}checked{{ end }}>
<label for="{{ printf "navtree-%s" $id }}" class="flex justify-between">
{{ end }}
<span class="flex">
{{ if $icon }}<svg class="icon {{ .icon }}"><use xlink:href="#{{ .icon }}"></use></svg>{{ end }}
<a href="{{ if .external }}{{ .ref }}{{ else }}{{ relref $current .ref }}{{ end }}"
class="gdoc-nav__entry {{ if not .external }}{{ if $isCurrent }}is-active{{ end }}{{ end }}">
{{ .name }}
</a>
</span>
{{ if $hasCollapse }}
<svg class="icon gdoc_keyborad_arrow_left"><use xlink:href="#gdoc_keyborad_arrow_left"></use></svg>
<svg class="icon gdoc_keyborad_arrow_down hidden"><use xlink:href="#gdoc_keyborad_arrow_down"></use></svg>
</label>
{{ end }}
{{ else }}
<span class="flex">{{ .name }}</span>
{{ end }}
{{ with .sub }}
{{ template "menu-file" dict "sect" . "current" ($current.Scratch.Get "current") "site" ($current.Scratch.Get "site") }}
{{ end }}
</li>
{{ end }}
</ul>
{{ end }}