71 lines
2.6 KiB
HTML
71 lines
2.6 KiB
HTML
{{- $isExternal := strings.HasPrefix .Destination "http" -}}
|
|
{{- $parsed := urls.Parse .Destination -}}
|
|
{{- $host := $parsed.Host -}}
|
|
{{- $path := $parsed.Path -}}
|
|
{{- $query := $parsed.RawQuery -}}
|
|
{{- $page := .Page -}}
|
|
{{- $site := $page.Site -}}
|
|
{{- $aff := index $site.Data.affiliates.sites $host -}}
|
|
{{- $isAffiliated := false -}}
|
|
{{- $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 -}}
|
|
{{- $newURL := .Destination -}}
|
|
{{- if and $isExternal $aff -}}
|
|
{{- $param := $aff.param -}}
|
|
{{- $value := $aff.value -}}
|
|
{{- $isAffiliated = true -}}
|
|
{{- if $query -}}
|
|
{{- $newURL = printf "%s://%s%s?%s&%s=%s" $parsed.Scheme $host $path $query $param $value -}}
|
|
{{- else -}}
|
|
{{- $newURL = printf "%s://%s%s?%s=%s" $parsed.Scheme $host $path $param $value -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- $titlePrefix := cond $isAffiliated "Lien affilié" (cond $isExternal "Lien externe" "") -}}
|
|
{{- $classes := slice -}}
|
|
{{- if $isExternal -}}
|
|
{{- $classes = $classes | append "external" -}}
|
|
{{- if $isAffiliated -}}
|
|
{{- $classes = $classes | append "affiliated" -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- if $isDeadLink -}}
|
|
{{- $classes = $classes | append "dead" -}}
|
|
{{- end -}}
|
|
{{- $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>
|
|
{{- /* */ -}}
|