SandpointsTheme/layouts/_default/_markup/render-link.html

30 lines
1.4 KiB
HTML
Raw Normal View History

2025-04-18 12:05:39 +02:00
{{- $currentPage := .Page -}}
2025-04-20 00:01:16 +02:00
{{- $text := .Text -}}
{{- $destination := .Destination -}}
{{- $u := urls.Parse $destination -}}
2025-04-18 12:05:39 +02:00
{{- if not $u.Scheme -}}
2025-04-21 12:27:03 +02:00
{{- $page := site.GetPage $destination -}}
{{- if $page -}}
{{- $backlinks := $page.Store.Get "backlinks" | default slice -}}
2025-04-18 12:05:39 +02:00
{{- $backlinks := $backlinks|append $currentPage.RelPermalink -}}
2025-04-21 12:27:03 +02:00
{{- $page.Store.Set "backlinks" ($backlinks|uniq) -}}
2025-04-20 00:01:16 +02:00
{{- if not $text -}}
2025-04-21 12:27:03 +02:00
{{- $text = $page.LinkTitle -}}
2025-04-20 00:01:16 +02:00
{{- end -}}
2025-04-21 12:27:03 +02:00
<span class="supt">{{- $page.Section -}}</span><a href="{{- $page.RelPermalink -}}" {{- with $page.Title }} title="{{ . }}"{{ end -}}>{{- $text -}}</a>
{{- else if hasPrefix $destination "/library" -}}
2025-04-20 00:01:16 +02:00
{{- $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>
2025-04-21 12:27:03 +02:00
{{- else -}}
{{- warnf "In %s broken link: %s" $currentPage.RelPermalink $destination -}}
2025-04-20 00:01:16 +02:00
{{- end -}}
{{- else -}}
2025-04-21 12:27:03 +02:00
<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>
2025-04-18 12:05:39 +02:00
{{- end -}}
{{- /* chomp trailing newline */ -}}