{{/* Every relationship of a specification, outbound and derived inbound, grouped by relation type and direction, in the order of params.relations. Returns a slice of dict: key, label, hint, dir (out|in|both), pages. */}} {{ $page := . }} {{ $slug := .File.ContentBaseName }} {{ $specs := partialCached "spec/all.html" "all" }} {{ $groups := slice }} {{/* A neighbour is listed once, under the first relationship that names it. */}} {{ $seen := slice }} {{ range site.Params.relations }} {{ $rel := . }} {{ $key := .key }} {{ $out := slice }} {{ with $page.Params.relations }} {{ with index . $key }} {{ range . }} {{ with site.GetPage (printf "/specs/%s" .) }} {{ $out = $out | append . }} {{ else }} {{ warnf "%s: relation %s points at unknown specification %q" $page.File.Path $key . }} {{ end }} {{ end }} {{ end }} {{ end }} {{ $in := slice }} {{ range $specs }} {{ $other := . }} {{ with .Params.relations }} {{ with index . $key }} {{ if in . $slug }}{{ $in = $in | append $other }}{{ end }} {{ end }} {{ end }} {{ end }} {{ $fresh := slice }}{{ range $out }}{{ if not (in $seen .) }}{{ $fresh = $fresh | append . }}{{ end }}{{ end }} {{ $out = $fresh }}{{ $seen = $seen | append $out }} {{ $fresh = slice }}{{ range $in }}{{ if not (in $seen .) }}{{ $fresh = $fresh | append . }}{{ end }}{{ end }} {{ $in = $fresh }}{{ $seen = $seen | append $in }} {{ if eq $rel.label $rel.inverse }} {{ $both := $out }} {{ range $in }}{{ if not (in $both .) }}{{ $both = $both | append . }}{{ end }}{{ end }} {{ with $both }}{{ $groups = $groups | append (dict "key" $key "label" $rel.label "hint" $rel.hint "dir" "both" "pages" .) }}{{ end }} {{ else }} {{ with $out }}{{ $groups = $groups | append (dict "key" $key "label" $rel.label "hint" $rel.hint "dir" "out" "pages" .) }}{{ end }} {{ with $in }}{{ $groups = $groups | append (dict "key" $key "label" $rel.inverse "hint" $rel.hint "dir" "in" "pages" .) }}{{ end }} {{ end }} {{ end }} {{ return $groups }}