SandpointsTheme/layouts/partials/single-page-graph.html
2025-05-04 15:11:06 +02:00

38 lines
1.7 KiB
HTML

{{- $currentPage := . -}}
{{- $currentEntry := dict -}}
{{- $menuPrefix := "" -}}
{{- $section := "" -}}
{{- range $sectionMaybe, $pagesMaybe := $currentPage.Params -}}
{{- if strings.Contains $sectionMaybe "_" -}}
{{- $sectionsSlice := split (strings.TrimPrefix "_" $sectionMaybe) "_" -}}
{{- if gt (len $sectionsSlice) 0 -}}
{{- $pluralSection := index (last 1 $sectionsSlice) 0 -}}
{{- $section = partial "GetSingularSectionName.html" $pluralSection -}}
{{- with (where site.Pages "Section" $section) -}}
{{- $menuPrefix = "no-prefix" -}}
{{- if gt (len $sectionsSlice) 1 -}}
{{- $menuPrefix = delimit (first (sub (len $sectionsSlice) 1) $sectionsSlice) " " -}}
{{- else -}}
{{- end -}}
{{- if reflect.IsSlice $pagesMaybe -}}
{{- range $pageMaybe := $pagesMaybe -}}
{{- $pageMaybeRelPermalink := (printf "/%s/%s" $section $pageMaybe) -}}
{{- $page := site.GetPage $pageMaybeRelPermalink -}}
{{- if $page -}}
{{- $currentPages := index $currentEntry $menuPrefix | default slice -}}
{{- $currentPages = $currentPages | append $page.RelPermalink -}}
{{- $currentEntry = merge $currentEntry (dict $menuPrefix $currentPages) -}}
{{- else -}}
{{- with $currentPage.File -}}
{{- warnf "In /%s '%s' is missing %s" .Path $sectionMaybe $pageMaybeRelPermalink -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if gt (len $currentEntry) 0 -}}
{{- $currentPage.Store.Set "graph" $currentEntry -}}
{{- end -}}