{{- $entries := newScratch -}} {{- $sections := newScratch -}} {{- $parentVerbs := slice "has" -}} {{- with site.Params.sandpoints -}} {{- if isset . "parentverbs" -}}{{- $parentVerbs = .parentVerbs -}}{{- end -}} {{- end -}} {{- $inverseLabels := newScratch -}} {{- $inverseLabels.Set "has" "is in" -}} {{- range $verb, $label := site.Params.sandpoints.inverses -}}{{- $inverseLabels.Set $verb $label -}}{{- end -}} {{- $inverseLabels.Set "no-prefix" "mentioned in" -}} {{- range site.Pages -}} {{- $entries.Set .Path (dict "relations" slice "forward" dict "params" dict "nouns" dict "inverses" dict "parents" slice "children" slice "depth" 0) -}} {{- end -}} {{- range site.Pages -}} {{- $source := . -}} {{- $relations := slice -}} {{- $forward := newScratch -}} {{- $params := newScratch -}} {{- $nouns := newScratch -}} {{- $children := slice -}} {{- range $key, $value := .Params -}} {{- if and (strings.Contains $key "_") (reflect.IsSlice $value) -}} {{- $words := split (strings.TrimPrefix "_" $key) "_" -}} {{- $section := partialCached "GetSingularSectionName.html" (index (last 1 $words) 0) (index (last 1 $words) 0) site.Language.Lang -}} {{- if $section -}} {{- $sections.Set $key $section -}} {{- $verb := "no-prefix" -}} {{- if gt (len $words) 1 -}}{{- $verb = delimit (first (sub (len $words) 1) $words) " " -}}{{- end -}} {{- $paths := slice -}} {{- range $value -}} {{- $target := printf "/%s/%s" $section . -}} {{- with site.GetPage $target -}} {{- $paths = $paths | append .Path -}} {{- $targetPath := .Path -}} {{- with $inverseLabels.Get $verb -}} {{- $label := . -}} {{- $inverses := newScratch -}} {{- range $name, $paths := ($entries.Get $targetPath).inverses -}}{{- $inverses.Set $name $paths -}}{{- end -}} {{- $inverses.Set $label (union ($inverses.Get $label | default slice) (slice $source.Path)) -}} {{- $entries.SetInMap $targetPath "inverses" $inverses.Values -}} {{- end -}} {{- if in $parentVerbs $verb -}} {{- $parents := ($entries.Get $targetPath).parents -}} {{- $entries.SetInMap $targetPath "parents" (union $parents (slice $source.Path)) -}} {{- end -}} {{- else -}} {{- warnf "In %s '%s' is missing %s" (partial "page-source.html" $source) $key $target -}} {{- end -}} {{- end -}} {{- $params.Set $key $paths -}} {{- $forward.Set $verb (union ($forward.Get $verb | default slice) $paths) -}} {{- $parent := in $parentVerbs $verb -}} {{- if $parent -}}{{- $children = union $children $paths -}}{{- end -}} {{- if eq $verb "no-prefix" -}}{{- $nouns.Set $section (union ($nouns.Get $section | default slice) $paths) -}}{{- end -}} {{- $relations = $relations | append (dict "key" $key "verb" $verb "section" $section "paths" $paths "parent" $parent) -}} {{- end -}} {{- end -}} {{- end -}} {{- $entries.SetInMap .Path "relations" $relations -}} {{- $entries.SetInMap .Path "forward" $forward.Values -}} {{- $entries.SetInMap .Path "params" $params.Values -}} {{- $entries.SetInMap .Path "nouns" $nouns.Values -}} {{- $entries.SetInMap .Path "children" $children -}} {{- end -}} {{- range seq (len site.Pages) -}} {{- $changed := false -}} {{- range $path, $entry := $entries.Values -}} {{- $depth := 0 -}} {{- range $entry.parents -}}{{- $depth = math.Max $depth (add ($entries.Get .).depth 1) -}}{{- end -}} {{- if ne (int $depth) (int $entry.depth) -}} {{- $changed = true -}} {{- $entries.SetInMap $path "depth" (int $depth) -}} {{- end -}} {{- end -}} {{- if not $changed -}}{{- break -}}{{- end -}} {{- end -}} {{- return (dict "pages" $entries.Values "sections" $sections.Values) -}}