From c972ba977628b8707e6de681c8b8eb72ad3a9353 Mon Sep 17 00:00:00 2001 From: Marcell Mars Date: Mon, 21 Apr 2025 12:27:03 +0200 Subject: [PATCH] report broken links --- layouts/_default/_markup/render-link.html | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/layouts/_default/_markup/render-link.html b/layouts/_default/_markup/render-link.html index f2820a7..9a0ecca 100644 --- a/layouts/_default/_markup/render-link.html +++ b/layouts/_default/_markup/render-link.html @@ -4,24 +4,26 @@ {{- $u := urls.Parse $destination -}} {{- if not $u.Scheme -}} - {{- with site.GetPage .Destination -}} - {{- $backlinks := .Store.Get "backlinks" | default slice -}} + {{- $page := site.GetPage $destination -}} + {{- if $page -}} + {{- $backlinks := $page.Store.Get "backlinks" | default slice -}} {{- $backlinks := $backlinks|append $currentPage.RelPermalink -}} - {{- .Store.Set "backlinks" ($backlinks|uniq) -}} + {{- $page.Store.Set "backlinks" ($backlinks|uniq) -}} {{- if not $text -}} - {{- $text = .LinkTitle -}} + {{- $text = $page.LinkTitle -}} {{- end -}} - {{- .Section -}}⁄{{- $text -}} - {{- end -}} - {{- if hasPrefix $destination "/library" -}} + {{- $page.Section -}}⁄{{- $text -}} + {{- 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 -}} library⁄{{- $text -}} + {{- else -}} + {{- warnf "In %s broken link: %s" $currentPage.RelPermalink $destination -}} {{- end -}} {{- else -}} - www⁄{{- with .Text }}{{ . }}{{- end -}} + www⁄{{- if .Text }}{{ .Text }}{{- else -}}{{- .Destination -}}{{- end -}} {{- end -}} {{- /* chomp trailing newline */ -}}