{{ define "section-tree-nav" }}
{{ $showvisitedlinks := .showvisitedlinks }}
{{ $currentNode := .currentnode }}
{{ $currentFileUniqueID := "" }}
{{ $alwaysopen := .alwaysopen }}
{{ with $currentNode.File }}{{ $currentFileUniqueID = .UniqueID }}{{ end }}
{{with .sect}}
{{if and .IsSection (or (not .Params.hidden) $.showhidden)}}
{{safeHTML .Params.head}}
{{ $currentAlwaysopen := .Params.alwaysopen | default $alwaysopen }}
{{ partial "menu-pre.html" . }}{{or .Params.menuTitle .LinkTitle .Title}}{{ partial "menu-post.html" . }}
{{ if $showvisitedlinks}}{{end}}
{{ $numberOfPages := (add (len ( where .Pages "Params.hidden" "ne" true )) (len ( where .Sections "Params.hidden" "ne" true ))) }}
{{ if ne $numberOfPages 0 }}
{{ $currentNode.Scratch.Set "pages" .Pages }}
{{ if .Sections}}
{{ $currentNode.Scratch.Set "pages" (.Pages | union .Sections) }}
{{end}}
{{ $pages := ($currentNode.Scratch.Get "pages") }}
{{if eq .Site.Params.ordersectionsby "title"}}
{{ range $pages.ByTitle }}
{{ if and .Params.hidden (not $.showhidden) }}
{{else}}
{{ template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" true}}
{{end}}
{{ end }}
{{else}}
{{ range $pages.ByWeight }}
{{ if and .Params.hidden (not $.showhidden) }}
{{else}}
{{ template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" true}}
{{end}}
{{ end }}
{{end}}
{{ end }}
{{else if not .Params.Hidden }}
{{ partial "menu-pre.html" . }}{{or .Params.menuTitle .LinkTitle .Title}}{{ partial "menu-post.html" . }}
{{ if $showvisitedlinks}}{{end}}
{{end}}
{{ end }}
{{ end }}