{{- $currentPage := .PageInner | default .Page -}}
{{- $text := .Text -}}
{{- $destination := .Destination -}}
{{- $reference := dict "kind" "media" "destination" $destination -}}
{{- if strings.HasPrefix $destination "img:" -}}
{{- $img_params := (substr $destination 4) -}}
{{- $img_src := index (split $img_params " ") 0 -}}
{{- $img_attr := strings.TrimPrefix $img_src $img_params -}}
{{- else if strings.HasPrefix $destination "vid:" -}}
{{- $vid_params := (substr $destination 4) -}}
{{- $vid_src := index (split $vid_params " ") 0 -}}
{{- $vid_attr := strings.TrimPrefix $vid_src $vid_params -}}
{{- else if strings.HasPrefix $destination "bib:" -}}
{{- $bib := substr $destination 4 -}}
{{- $b := index hugo.Data.books.catalog $bib -}}
{{- $reference = dict "kind" "bibs" "destination" $destination "id" $bib "title" ($b.title | default $text) -}}
{{- $library := printf "%sBROWSE_LIBRARY.html" (site.Params.sandpoints.catalogPrefix | default "/library/") | relURL -}}
{{- if $b -}}
{{- if not $text -}}
{{- delimit $b.authors ", " " & " -}}{{- with $b.pubdate -}}, {{- substr . 0 4 -}}{{- end -}}. bib⁄{{- $b.title -}}. {{- with $b.publisher -}}{{- . -}}.{{- end -}}
{{- else -}}
bib⁄{{- $text -}}
{{- end -}}
{{- else -}}
{{- warnf "In %s bib:%s not found." (partial "page-source.html" $currentPage) $bib -}}
bib⁄{{- $text -}}
{{- end -}}
{{- else if strings.HasPrefix $destination "audio:" -}}
{{- $a_destination := substr $destination 6 -}}
{{- if findRE "^.*static" $a_destination -}}
{{ $text }}
{{- else -}}
{{ $text }}
{{- end -}}
{{- else -}}
{{- $u := urls.Parse $destination -}}
{{- if not $u.Scheme -}}
{{- $page := site.GetPage $destination -}}
{{- if $page -}}
{{- $reference = dict "kind" "internal" "destination" $destination "path" $page.Path -}}
{{- if not $text -}}
{{- $text = $page.LinkTitle | htmlEscape -}}
{{- end -}}
{{- partial "page-link.html" (dict "page" $page "text" $text "label" $page.Section) -}}
{{- else if findRE "^.*static" $destination -}}
{{- else -}}
{{- end -}}
{{- else -}}
{{- end -}}
{{- end -}}
{{- partial "content-reference.html" $reference -}}