1

Gestion et affichage des liens morts

This commit is contained in:
2025-11-11 17:27:52 +01:00
parent e533dc3fc1
commit 39dbd89397
13 changed files with 892 additions and 1356 deletions

View File

@@ -7,22 +7,16 @@
{{- $site := $page.Site -}}
{{- $aff := index $site.Data.affiliates.sites $host -}}
{{- $isAffiliated := false -}}
{{- $scratch := $page.Scratch -}}
{{- $externalCache := $scratch.Get "externalLinksCache" -}}
{{- if not $externalCache -}}
{{- $externalCache = dict -}}
{{- if fileExists "tools/cache/external_links.yaml" -}}
{{- with readFile "tools/cache/external_links.yaml" -}}
{{- $parsedCache := transform.Unmarshal . -}}
{{- if $parsedCache -}}
{{- $externalCache = $parsedCache -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $scratch.Set "externalLinksCache" $externalCache -}}
{{- $report := default (dict) (transform.Unmarshal (readFile "tools/cache/external_links.yaml")) -}}
{{- $deadList := default (slice) (index $report "links") -}}
{{- $entriesMap := default (dict) (index $report "entries") -}}
{{- $cacheEntry := index $entriesMap .Destination -}}
{{- $deadInfo := dict -}}
{{- $isDeadLink := false -}}
{{- with (first 1 (where $deadList "url" .Destination)) -}}
{{- $deadInfo = index . 0 -}}
{{- $isDeadLink = true -}}
{{- end -}}
{{- $cacheEntry := index $externalCache .Destination -}}
{{- $isDeadLink := and $cacheEntry (eq (index $cacheEntry "manually_killed") true) -}}
{{- $newURL := .Destination -}}
{{- if and $isExternal $aff -}}
{{- $param := $aff.param -}}
@@ -34,12 +28,7 @@
{{- $newURL = printf "%s://%s%s?%s=%s" $parsed.Scheme $host $path $param $value -}}
{{- end -}}
{{- end -}}
{{- $titlePrefix := "" -}}
{{- if $isAffiliated -}}
{{- $titlePrefix = "Lien affilié" -}}
{{- else if $isExternal -}}
{{- $titlePrefix = "Lien externe" -}}
{{- end -}}
{{- $titlePrefix := cond $isAffiliated "Lien affilié" (cond $isExternal "Lien externe" "") -}}
{{- $classes := slice -}}
{{- if $isExternal -}}
{{- $classes = $classes | append "external" -}}
@@ -50,9 +39,32 @@
{{- if $isDeadLink -}}
{{- $classes = $classes | append "dead" -}}
{{- end -}}
<a href="{{ $newURL }}" title="{{ $titlePrefix }}{{ .Title }}"
{{- $titleParts := slice -}}
{{- with $titlePrefix -}}
{{- $titleParts = $titleParts | append . -}}
{{- end -}}
{{- with .Title -}}
{{- $titleParts = $titleParts | append . -}}
{{- end -}}
{{- if $isDeadLink -}}
{{- $deadDetails := slice -}}
{{- with (index $cacheEntry "checkedAt") -}}
{{- $deadDetails = $deadDetails | append (printf "inaccessible depuis le %s" (time.Format "02/01/2006" (time .))) -}}
{{- end -}}
{{- with (index $cacheEntry "errorType") -}}
{{- $deadDetails = $deadDetails | append (printf "raison %s" .) -}}
{{- end -}}
{{- with (index $deadInfo "status") -}}
{{- $deadDetails = $deadDetails | append (printf "statut %v" .) -}}
{{- end -}}
{{- with $deadDetails -}}
{{- $titleParts = $titleParts | append (printf "(%s)" (delimit . " ; ")) -}}
{{- end -}}
{{- end -}}
{{- $titleValue := delimit $titleParts " - " -}}
<a href="{{ $newURL }}" title="{{ $titleValue }}"
{{- if $isExternal -}} rel="noreferrer"{{- end -}}
{{- if gt (len $classes) 0 -}} class="{{ delimit $classes ` ` }}"{{- end -}}>
{{- .Text | safeHTML -}}
</a>
{{- /* */ -}}
{{- /* */ -}}