{{- $contentType := "all"}}
{{- if eq (.Get "type") "section" }}
{{- $contentType = "section" }}
{{- end}}
{{- $depthLimit := 2 }}
{{- with .Get "depth" }}
{{- $depthLimit = . }}
{{- end }}
{{- $startSection := .Page.Page }}
{{- template "sectioncontent-loop" dict "startSection" $startSection "currentSection" $startSection "contentType" $contentType "depthLimit" $depthLimit "depthCnt" 0 }}
{{- define "sectioncontent-loop" }}
{{- $startSection := .startSection }}
{{- $currentSection := .currentSection }}
{{- $contentType := .contentType }}
{{- $depthLimit := .depthLimit }}
{{- $depthCnt := add .depthCnt 1 }}
{{- with .startSection }}
{{- with $currentSection }}
{{- if and (ne $startSection $currentSection) (or (ne $contentType "section") .IsSection) }}
{{- if .LinkTitle }}
{{- .LinkTitle }}
{{- else }}
{{- replace .File.Dir .Parent.File.Dir "" | replaceRE "/" "-" | replaceRE "-$" ":" }}
{{- .File.TranslationBaseName }}
{{- end }}
{{- end }}
{{- end }}
{{- if le $depthCnt $depthLimit }}
{{- $elem := dict }}
{{- range .Site.Pages }}
{{- if and (eq .CurrentSection $currentSection.CurrentSection) (ne $currentSection .) (ne $startSection .) (.IsDescendant $currentSection) }}
{{- $elem = merge $elem (dict (string .) .) }}
{{- else if and (eq $currentSection .Parent) (.IsSection) (ne .CurrentSection $currentSection.CurrentSection) (ne $startSection .) (.IsDescendant $currentSection) }}
{{- $elem = merge $elem (dict (string .) .) }}
{{- end }}
{{- end }}
{{- range $elem }}
{{- template "sectioncontent-loop" dict "startSection" $startSection "currentSection" . "contentType" $contentType "depthLimit" $depthLimit "depthCnt" $depthCnt }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}