SandpointsTheme/layouts/_default/_markup/render-link.html
2025-04-21 12:27:03 +02:00

29 lines
1.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{{- $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 -}}
<span class="supt">{{- $page.Section -}}</span><a href="{{- $page.RelPermalink -}}" {{- with $page.Title }} title="{{ . }}"{{ end -}}>{{- $text -}}</a>
{{- else if hasPrefix $destination "/library" -}}
{{- $bib := strings.TrimPrefix "/library/" $destination -}}
{{- $b := index site.Data.books.catalog $bib -}}
{{- if not $text -}}
{{- $text = $b.title|default "" -}}
{{- end -}}
<span class="supt">library</span><a href="/library/BROWSE_LIBRARY.html#/books/{{- $bib -}}">{{- $text -}}</a>
{{- else -}}
{{- warnf "In %s broken link: %s" $currentPage.RelPermalink $destination -}}
{{- end -}}
{{- else -}}
<span class="supt">www</span><a href="{{ .Destination | safeURL }}"{{- with .Title }} title="{{ . }}"{{ end -}}{{- if $u.IsAbs }} rel="external"{{ end -}}>{{- if .Text }}{{ .Text }}{{- else -}}{{- .Destination -}}{{- end -}}</a>
{{- end -}}
{{- /* chomp trailing newline */ -}}