1{{ define "main" }}
2 <h2>Backlinks, outgoing URLs, bibliographic references and internal links:</h2>
3 <button class="report-toggle" type="button" onclick="const entries=document.querySelectorAll('details');const open=[...entries].some(e=>!e.open);entries.forEach(e=>e.open=open)">[toggle expand/collapse]</button><p></p>
4 {{- with templates.Defer -}}
5 {{- $graph := partialCached "graph.html" site site.Language.Lang -}}
6 {{- $prefix := site.Params.sandpoints.catalogPrefix | default "/library/" -}}
7 {{- range site.RegularPages -}}
8 {{- $page := . -}}
9 {{- $entry := index $graph.pages .Path -}}
10 {{- $mentioned := slice -}}
11 {{- range $label := slice "is in" "mentioned in" -}}{{- $mentioned = union $mentioned (index $entry.inverses $label | default slice) -}}{{- end -}}
12 {{- range $label, $paths := $entry.inverses -}}{{- $mentioned = union $mentioned $paths -}}{{- end -}}
13 {{- $mentioned = union $mentioned (index (partialCached "content-backlinks.html" site site.Language.Lang) .Path | default slice) -}}
14 {{- $internal := slice -}}
15 {{- range $entry.forward -}}{{- $internal = union $internal . -}}{{- end -}}
16 {{- $external := slice -}}{{- $library := slice -}}{{- $other := slice -}}{{- $bibs := slice -}}
17 {{- $anchors := 0 -}}{{- $formats := 0 -}}
18 {{- range partialCached "page-references.html" . .Path .Language.Lang -}}
19 {{- if eq .kind "internal" -}}{{- $internal = union $internal (slice .path) -}}
20 {{- else if eq .kind "external" -}}{{- $external = $external | append .destination -}}
21 {{- else if eq .kind "library" -}}{{- $library = $library | append .destination -}}
22 {{- else if eq .kind "bibs" -}}{{- $bibs = $bibs | append . -}}
23 {{- else if eq .kind "anchors" -}}{{- $anchors = add $anchors 1 -}}
24 {{- else if eq .kind "formats" -}}{{- $formats = add $formats 1 -}}
25 {{- else if eq .kind "other" -}}{{- $other = $other | append .destination -}}{{- end -}}
26 {{- end -}}
27 <details data-page="{{ .RelPermalink }}" data-anchors="{{ $anchors }}" data-formats="{{ $formats }}">
28 <summary>{{ partial "page-link.html" (dict "page" . "label" .Section) }}</summary>
29 {{- range slice (dict "name" "mentioned" "title" "Mentioned in other Sandpoints pages" "paths" $mentioned) (dict "name" "internal" "title" "Internal links to other Sandpoint pages" "paths" ($internal | uniq)) -}}
30 {{- if .paths -}}<details data-group="{{ .name }}" data-count="{{ len .paths }}"><summary>{{ .title }} ({{ len .paths }}):</summary><ul>
31 {{- range .paths -}}{{- with site.GetPage . -}}<li>{{ partial "page-link.html" (dict "page" . "label" .Section) }}</li>{{- end -}}{{- end -}}
32 </ul></details>{{- end -}}
33 {{- end -}}
34 {{- with $external -}}<details data-group="external" data-count="{{ len . }}"><summary>Outgoing links to other pages on Internet ({{ len . }}):</summary><ul>
35 {{- range . -}}<li><span class="supt">www⁄</span><a href="{{ . | safeURL }}" rel="external">{{ . }}</a></li>{{- end -}}
36 </ul></details>{{- end -}}
37 {{- with $library -}}<details data-group="library" data-count="{{ len . }}"><summary>Links to Sandpoint's library ({{ len . }}):</summary><ul>
38 {{- range . -}}<li><span class="supt">lib⁄</span><a href="{{ printf "%sBROWSE_LIBRARY.html" $prefix | relURL }}#/book/{{ strings.TrimPrefix $prefix . }}">{{ . }}</a></li>{{- end -}}
39 </ul></details>{{- end -}}
40 {{- with $bibs -}}<details data-group="bibs" data-count="{{ len . }}"><summary>Bibliographic references ({{ len . }}):</summary><ul>
41 {{- range . -}}<li><span class="supt">bib⁄</span><a href="{{ printf "%sBROWSE_LIBRARY.html" $prefix | relURL }}#/book/{{ .id }}">{{ .title }}</a></li>{{- end -}}
42 </ul></details>{{- end -}}
43 {{- $remaining := add (add $anchors $formats) (len $other) -}}
44 {{- if $remaining -}}<details><summary>Anchor, formatting and other links ({{ $remaining }}):</summary><ul>
45 <li data-group="formats" data-count="{{ $formats }}">{{ $formats }} formatting links.</li>
46 <li data-group="anchors" data-count="{{ $anchors }}">{{ $anchors }} anchor links.</li>
47 <li data-group="other" data-count="{{ len $other }}"><ul>
48 {{- range $other -}}<li><span class="supt">other⁄</span>{{ with site.GetPage . }}{{ partial "page-link.html" (dict "page" .) }}{{ else }}{{ . }}{{ end }}</li>{{- end -}}
49 </ul></li>
50 </ul></details>{{- end -}}
51 </details>
52 {{- end -}}
53 {{- end -}}
54{{ end }}