From 53fd25a880023d1bb04bea26534ad92f17cd1e1d Mon Sep 17 00:00:00 2001 From: Marcell Mars Date: Mon, 31 Mar 2025 15:49:04 +0200 Subject: [PATCH] defer on site.AllPages. add mentioned_in --- layouts/partials/deferred_page_graph.html | 32 +++++++++++++++++++---- layouts/partials/single-page-graph.html | 17 ++++++------ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/layouts/partials/deferred_page_graph.html b/layouts/partials/deferred_page_graph.html index 7f2a0d7..9d0eb15 100644 --- a/layouts/partials/deferred_page_graph.html +++ b/layouts/partials/deferred_page_graph.html @@ -1,8 +1,30 @@ {{ $currentPage := . }} -{{ $pageGraph := $currentPage.Store.Get "graph"}} -

{{ printf "%#v" $pageGraph }}

+{{ $currentPageGraph := $currentPage.Store.Get "graph"}} +

{{ printf "%#v" $currentPageGraph }}

-{{- with templates.Defer -}} - {{ $pageIsIn := $currentPage.Store.Get "isin"}} -

{{ printf "%#v" $pageIsIn }}

+{{ $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 -}} diff --git a/layouts/partials/single-page-graph.html b/layouts/partials/single-page-graph.html index 241ad78..4ead7ed 100644 --- a/layouts/partials/single-page-graph.html +++ b/layouts/partials/single-page-graph.html @@ -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 -}}