defer on site.AllPages. add mentioned_in

This commit is contained in:
Marcell Mars 2025-03-31 15:49:04 +02:00
parent 4b48238689
commit 53fd25a880
2 changed files with 36 additions and 13 deletions

View file

@ -1,8 +1,30 @@
{{ $currentPage := . }} {{ $currentPage := . }}
{{ $pageGraph := $currentPage.Store.Get "graph"}} {{ $currentPageGraph := $currentPage.Store.Get "graph"}}
<p>{{ printf "%#v" $pageGraph }}</p> <p>{{ printf "%#v" $currentPageGraph }}</p>
{{- with templates.Defer -}} {{ $data := (dict "allPages" site.AllPages "currentPage" $currentPage)}}
{{ $pageIsIn := $currentPage.Store.Get "isin"}} {{- with (templates.Defer (dict "data" $data)) -}}
<p>{{ printf "%#v" $pageIsIn }}</p> {{ range .allPages }}
{{- $page := . -}}
{{- $pageGraph := $page.Store.Get "graph" -}}
{{- range $child := index $pageGraph "has" -}}
{{- $childPage := site.GetPage $child -}}
{{- $isinPages := $childPage.Store.Get "isin" | default slice -}}
{{- $isinPages = $isinPages | append $page.RelPermalink -}}
{{- $childPage.Store.Set "isin" ($isinPages|uniq) -}}
{{- end -}}
{{- range $kid := index $pageGraph "no-prefix" -}}
{{- $mentionedInPage := site.GetPage $kid -}}
{{- $mentionedIn := $mentionedInPage.Store.Get "mentioned_in" | default slice -}}
{{- $mentionedIn = $mentionedIn | append $page.RelPermalink -}}
{{- $mentionedInPage.Store.Set "mentioned_in" ($mentionedIn|uniq) -}}
{{- end -}}
{{- end -}}
{{- printf "%s is in %#v" .currentPage.RelPermalink (.currentPage.Store.Get "isin") -}}
{{- printf "%s mentioned in %#v" .currentPage.RelPermalink (.currentPage.Store.Get "mentioned_in") -}}
{{- warnf "%s is in %#v" .currentPage.RelPermalink (.currentPage.Store.Get "isin") -}}
{{- warnf "%s mentioned in %#v" .currentPage.RelPermalink (.currentPage.Store.Get "mentioned_in") -}}
{{- end -}} {{- end -}}

View file

@ -5,7 +5,7 @@
{{- $menuPrefix := "" -}} {{- $menuPrefix := "" -}}
{{- $section := "" -}} {{- $section := "" -}}
{{- range $sectionMaybe, $pages := $currentPage.Params -}} {{- range $sectionMaybe, $pagesMaybe := $currentPage.Params -}}
{{- if strings.Contains $sectionMaybe "_" -}} {{- if strings.Contains $sectionMaybe "_" -}}
{{- $sectionsSlice := split (strings.TrimPrefix "_" $sectionMaybe) "_" -}} {{- $sectionsSlice := split (strings.TrimPrefix "_" $sectionMaybe) "_" -}}
{{- if gt (len $sectionsSlice) 0 -}} {{- if gt (len $sectionsSlice) 0 -}}
@ -21,15 +21,16 @@
{{- $menuPrefix = delimit (first (sub (len $sectionsSlice) 1) $sectionsSlice) " " -}} {{- $menuPrefix = delimit (first (sub (len $sectionsSlice) 1) $sectionsSlice) " " -}}
{{- else -}} {{- else -}}
{{- end -}} {{- end -}}
{{- if reflect.IsSlice $pages -}} {{- if reflect.IsSlice $pagesMaybe -}}
{{- range $page := $pages -}} {{- range $pageMaybe := $pagesMaybe -}}
{{- with site.GetPage (printf "%s/%s" $section $page) -}} {{- $pageMaybeRelPermalink := (printf "%s/%s" $section $pageMaybe) -}}
{{- $page := site.GetPage $pageMaybeRelPermalink -}}
{{- if $page -}}
{{- $currentPages := index $currentEntry $menuPrefix | default slice -}} {{- $currentPages := index $currentEntry $menuPrefix | default slice -}}
{{- $currentPages = $currentPages | append .RelPermalink -}} {{- $currentPages = $currentPages | append $page.RelPermalink -}}
{{- $currentEntry = merge $currentEntry (dict $menuPrefix $currentPages) -}} {{- $currentEntry = merge $currentEntry (dict $menuPrefix $currentPages) -}}
{{- else -}}
{{- $isInSlice := .Store.Get "isin" | default slice -}} {{- warnf "Missing '%s' from '%s' of '%s'." $pageMaybeRelPermalink $sectionMaybe $currentPage.RelPermalink -}}
{{ .Store.Add "isin" (slice $currentPage.RelPermalink) }}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}