1{{- $entries := newScratch -}}
2{{- $sections := newScratch -}}
3{{- $parentVerbs := slice "has" -}}
4{{- with site.Params.sandpoints -}}
5 {{- if isset . "parentverbs" -}}{{- $parentVerbs = .parentVerbs -}}{{- end -}}
6{{- end -}}
7{{- $inverseLabels := newScratch -}}
8{{- $inverseLabels.Set "has" "is in" -}}
9{{- range $verb, $label := site.Params.sandpoints.inverses -}}{{- $inverseLabels.Set $verb $label -}}{{- end -}}
10{{- $inverseLabels.Set "no-prefix" "mentioned in" -}}
11{{- range site.Pages -}}
12 {{- $entries.Set .Path (dict "relations" slice "forward" dict "params" dict "nouns" dict "inverses" dict "parents" slice "children" slice "depth" 0) -}}
13{{- end -}}
14{{- range site.Pages -}}
15 {{- $source := . -}}
16 {{- $relations := slice -}}
17 {{- $forward := newScratch -}}
18 {{- $params := newScratch -}}
19 {{- $nouns := newScratch -}}
20 {{- $children := slice -}}
21 {{- range $key, $value := .Params -}}
22 {{- if and (strings.Contains $key "_") (reflect.IsSlice $value) -}}
23 {{- $words := split (strings.TrimPrefix "_" $key) "_" -}}
24 {{- $section := partialCached "GetSingularSectionName.html" (index (last 1 $words) 0) (index (last 1 $words) 0) site.Language.Lang -}}
25 {{- if $section -}}
26 {{- $sections.Set $key $section -}}
27 {{- $verb := "no-prefix" -}}
28 {{- if gt (len $words) 1 -}}{{- $verb = delimit (first (sub (len $words) 1) $words) " " -}}{{- end -}}
29 {{- $paths := slice -}}
30 {{- range $value -}}
31 {{- $target := printf "/%s/%s" $section . -}}
32 {{- with site.GetPage $target -}}
33 {{- $paths = $paths | append .Path -}}
34 {{- $targetPath := .Path -}}
35 {{- with $inverseLabels.Get $verb -}}
36 {{- $label := . -}}
37 {{- $inverses := newScratch -}}
38 {{- range $name, $paths := ($entries.Get $targetPath).inverses -}}{{- $inverses.Set $name $paths -}}{{- end -}}
39 {{- $inverses.Set $label (union ($inverses.Get $label | default slice) (slice $source.Path)) -}}
40 {{- $entries.SetInMap $targetPath "inverses" $inverses.Values -}}
41 {{- end -}}
42 {{- if in $parentVerbs $verb -}}
43 {{- $parents := ($entries.Get $targetPath).parents -}}
44 {{- $entries.SetInMap $targetPath "parents" (union $parents (slice $source.Path)) -}}
45 {{- end -}}
46 {{- else -}}
47 {{- warnf "In %s '%s' is missing %s" (partial "page-source.html" $source) $key $target -}}
48 {{- end -}}
49 {{- end -}}
50 {{- $params.Set $key $paths -}}
51 {{- $forward.Set $verb (union ($forward.Get $verb | default slice) $paths) -}}
52 {{- $parent := in $parentVerbs $verb -}}
53 {{- if $parent -}}{{- $children = union $children $paths -}}{{- end -}}
54 {{- if eq $verb "no-prefix" -}}{{- $nouns.Set $section (union ($nouns.Get $section | default slice) $paths) -}}{{- end -}}
55 {{- $relations = $relations | append (dict "key" $key "verb" $verb "section" $section "paths" $paths "parent" $parent) -}}
56 {{- end -}}
57 {{- end -}}
58 {{- end -}}
59 {{- $entries.SetInMap .Path "relations" $relations -}}
60 {{- $entries.SetInMap .Path "forward" $forward.Values -}}
61 {{- $entries.SetInMap .Path "params" $params.Values -}}
62 {{- $entries.SetInMap .Path "nouns" $nouns.Values -}}
63 {{- $entries.SetInMap .Path "children" $children -}}
64{{- end -}}
65{{- range seq (len site.Pages) -}}
66 {{- $changed := false -}}
67 {{- range $path, $entry := $entries.Values -}}
68 {{- $depth := 0 -}}
69 {{- range $entry.parents -}}{{- $depth = math.Max $depth (add ($entries.Get .).depth 1) -}}{{- end -}}
70 {{- if ne (int $depth) (int $entry.depth) -}}
71 {{- $changed = true -}}
72 {{- $entries.SetInMap $path "depth" (int $depth) -}}
73 {{- end -}}
74 {{- end -}}
75 {{- if not $changed -}}{{- break -}}{{- end -}}
76{{- end -}}
77{{- return (dict "pages" $entries.Values "sections" $sections.Values) -}}