Raw
 1{{- $currentPage := .PageInner | default .Page -}}
 2{{- $text := .Text -}}
 3{{- $destination := .Destination -}}
 4{{- $reference := dict "kind" "other" "destination" $destination -}}
 5{{- if and (hasPrefix $destination "{") (hasSuffix $destination "}") -}}
 6  {{- $reference = dict "kind" "formats" "destination" $destination -}}
 7  {{- $smallcaps := false -}}
 8  {{- range split (trim $destination "{}") "," -}}
 9    {{- $format := trim . " " -}}
10    {{- if eq $format "sc" -}}
11      {{- $smallcaps = true -}}
12    {{- else -}}
13      {{- warnf "In %s unknown format: %s" (partial "page-source.html" $currentPage) $format -}}
14    {{- end -}}
15  {{- end -}}
16  {{- if $smallcaps -}}<span class="smallcaps">{{ $text | safeHTML }}</span>{{- else -}}{{ $text | safeHTML }}{{- end -}}
17{{- else if hasPrefix $destination "#" -}}
18  {{- $reference = dict "kind" "anchors" "destination" $destination -}}
19  <span class="supt">§⁄</span><a class="anchor" href="{{ $destination | safeURL }}"{{ with .Title }} title="{{ . }}"{{ end }}>{{ $text | safeHTML }}</a>
20{{- else if hasPrefix $destination (site.Params.sandpoints.catalogPrefix | default "/library/") -}}
21  {{- $bib := strings.TrimPrefix (site.Params.sandpoints.catalogPrefix | default "/library/") $destination -}}
22  {{- $book := index hugo.Data.books.catalog $bib -}}
23  {{- if not $book.title -}}{{ warnf "In %s bib:%s not found." (partial "page-source.html" $currentPage) $bib }}{{- end -}}
24  {{- $reference = dict "kind" "library" "destination" $destination -}}
25  <span class="supt">bib⁄</span><a href="{{ printf "%sBROWSE_LIBRARY.html" (site.Params.sandpoints.catalogPrefix | default "/library/") | relURL }}#/book/{{ $bib }}">{{ $text | default $book.title | safeHTML }}</a>
26{{- else -}}
27  {{- $url := urls.Parse $destination -}}
28  {{- if not $url.Scheme -}}
29    {{- with site.GetPage $destination -}}
30      {{- $reference = dict "kind" "internal" "destination" $destination "path" .Path -}}
31      {{- partial "page-link.html" (dict "page" . "text" $text "label" .Section) -}}
32    {{- else -}}
33      {{- warnf "In %s broken link: %s" (partial "page-source.html" $currentPage) $destination -}}
34      <a href="{{ $destination | safeURL }}">{{ $text | default $destination | safeHTML }}</a>
35    {{- end -}}
36  {{- else -}}
37    {{- if not (in (slice "http" "https" "mailto") $url.Scheme) -}}
38      {{- warnf "In %s unsupported link scheme %s: %s" (partial "page-source.html" $currentPage) $url.Scheme $destination -}}
39    {{- end -}}
40    {{- if hasPrefix $destination "http" -}}{{- $reference = dict "kind" "external" "destination" $destination -}}<span class="supt">www⁄</span>{{- end -}}
41    <a href="{{ $destination | safeURL }}"{{ with .Title }} title="{{ . }}"{{ end }} rel="external">{{ $text | default $destination | safeHTML }}</a>
42  {{- end -}}
43{{- end -}}
44{{- partial "content-reference.html" $reference -}}