website/layouts/partials/tree.html
2020-08-16 21:52:55 +08:00

47 lines
1.3 KiB
HTML

<div>
<nav class='nav-menu'>
{{ $sections := .FirstSection.Sections.ByWeight }}
{{ $secondSection := .FirstSection }}
{{ $page := . }}
{{ range $sections }}
{{ if $page.IsDescendant . }}
{{ $secondSection = . }}
{{ end }}
{{ end }}
{{ template "section-tree-nav-section" (dict "page" . "section" $secondSection) }}
</nav>
</div>
{{ define "section-tree-nav-section" }}
{{ $s := .section }}
{{ $p := .page }}
{{ $list_active := $p.IsDescendant $s }}
{{ if eq $s.Parent $s.FirstSection }}
{{ else }}
<p class="list-title">
<span class="arrow {{ if $list_active }}arrow-open{{ end }}"></span>
<span>{{ $s.LinkTitle }}</span>
</p>
{{ end }}
<ul class="{{ if $list_active }}ul-active{{ end }}">
{{ $pages := where (union $s.Pages $s.Sections).ByWeight ".Params._build.render" "!=" false }}
{{ range $pages }}
{{ $active := eq . $p }}
<li class="list{{ if $active }} active{{ end }}">
{{ if .IsPage }}
<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
{{ else }}
{{ template "section-tree-nav-section" (dict "page" $p "section" .) }}
{{ end }}
</li>
{{ end }}
</ul>
{{ end }}
<script>
$('.nav-menu .list-title').click(function() {
$(this).find('.arrow').toggleClass('arrow-open')
$(this).next().toggleClass('ul-active')
})
</script>