{{- $currentPage := .Page -}}
{{- $text := .Text -}}
{{- $destination := .Destination -}}
{{- $u := urls.Parse $destination -}}
{{- if not $u.Scheme -}}
{{- $page := site.GetPage $destination -}}
{{- if $page -}}
{{- $backlinks := $page.Store.Get "backlinks" | default slice -}}
{{- $backlinks := $backlinks|append $currentPage.RelPermalink -}}
{{- $page.Store.Set "backlinks" ($backlinks|uniq) -}}
{{- if not $text -}}
{{- $text = $page.LinkTitle -}}
{{- end -}}
{{- $page.Section -}}⁄{{- $text -}}
{{- else if hasPrefix $destination "/library/" -}}
{{- $bib := strings.TrimPrefix "/library/" $destination -}}
{{- $b := index site.Data.books.catalog $bib -}}
{{- if not $b.title -}}
{{- with $currentPage.File -}}
{{- warnf "In /%s bib:%s not found." .Path $bib -}}
{{- end -}}
{{- end -}}
{{- if not $text -}}
{{- $text = $b.title|default "" -}}
{{- end -}}
library⁄{{- $text -}}
{{- else -}}
{{- with $currentPage.File -}}
{{- warnf "In /%s broken link: %s" .Path $destination -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- if hasPrefix $destination "http" -}}
www⁄
{{- end -}}{{- if .Text }}{{ .Text }}{{- else -}}{{- $destination -}}{{- end -}}
{{- end -}}
{{- /* chomp trailing newline */ -}}