{{- define "section-tree-nav" }}
{{- $showvisitedlinks := .showvisitedlinks }}
{{- $currentNode := .currentnode }}
{{- $currentFileUniqueID := "" }}
{{- $alwaysopen := .alwaysopen }}
{{- with $currentNode.File }}{{ $currentFileUniqueID = .UniqueID }}{{ end }}
{{- with .sect }}
{{- $hidden := and (eq (.Scratch.Get "relearnIsHiddenFromCurrent") true) (not $.showhidden) (not (.IsAncestor $currentNode)) }}
{{- if $hidden }}
{{- else if .IsSection }}
{{- safeHTML .Params.head }}
{{- $currentAlwaysopen := .Params.alwaysopen | default $alwaysopen }}
{{- partial "menu-pre.html" . }}{{ or .Params.menuTitle .LinkTitle .Title }}{{ partial "menu-post.html" . }}
{{- if $showvisitedlinks }}{{ end }}
{{- $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 }}
{{- template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" true}}
{{- end }}
{{- else }}
{{- range $pages.ByWeight }}
{{- template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" true}}
{{- end }}
{{- end }}
{{- else }}
{{- partial "menu-pre.html" . }}{{ or .Params.menuTitle .LinkTitle .Title }}{{ partial "menu-post.html" . }}
{{- if $showvisitedlinks }}{{ end }}
{{- end }}
{{- end }}
{{- end }}