{{- 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 }}
{{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
{{- $currentOrdersectionsby := .Params.ordersectionsby | default $defaultOrdersectionsby }}
{{- $currentAlwaysopen := .Params.alwaysopen | default $alwaysopen }}
{{- partial "menu-pre.html" . }}{{ or .Params.menuTitle .LinkTitle .Title }}{{ partial "menu-post.html" . }}
{{- if $showvisitedlinks }}{{ end }}
{{- $pages := .Pages }}
{{- if .Page.IsHome }}
{{- $pages = .Sections }}
{{- else if .Page.Sections}}
{{- $pages = (.Pages | union .Sections) }}
{{- end }}
{{- $defaultAlwaysopen := .Site.Params.alwaysopen | default true }}
{{- if eq $currentOrdersectionsby "title" }}
{{- range $pages.ByTitle }}
{{- template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen }}
{{- end }}
{{- else }}
{{- range $pages.ByWeight }}
{{- template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen }}
{{- end }}
{{- end }}
{{- else }}
{{- partial "menu-pre.html" . }}{{ or .Params.menuTitle .LinkTitle .Title }}{{ partial "menu-post.html" . }}
{{- if $showvisitedlinks }}{{ end }}
{{- end }}
{{- end }}
{{- end }}