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 := . }}
{{ $pageGraph := $currentPage.Store.Get "graph"}}
<p>{{ printf "%#v" $pageGraph }}</p>
{{ $currentPageGraph := $currentPage.Store.Get "graph"}}
<p>{{ printf "%#v" $currentPageGraph }}</p>
{{- with templates.Defer -}}
{{ $pageIsIn := $currentPage.Store.Get "isin"}}
<p>{{ printf "%#v" $pageIsIn }}</p>
{{ $data := (dict "allPages" site.AllPages "currentPage" $currentPage)}}
{{- with (templates.Defer (dict "data" $data)) -}}
{{ 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 -}}

View file

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