{{- $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 -}} {{- $newURL := .Destination -}} {{- $customClass := "" -}} {{- if reflect.IsMap . -}} {{- if isset . "Class" -}} {{- with (index . "Class") -}} {{- $customClass = . -}} {{- end -}} {{- end -}} {{- end -}} {{- if and $isExternal $aff -}} {{- $isAffiliated = true -}} {{- if $query -}} {{- $newURL = printf "%s://%s%s?%s&%s=%s" $parsed.Scheme $host $path $query $aff.param $aff.value -}} {{- else -}} {{- $newURL = printf "%s://%s%s?%s=%s" $parsed.Scheme $host $path $aff.param $aff.value -}} {{- end -}} {{- end -}} {{- $internalPage := "" -}} {{- $internalPageFound := false -}} {{- if not $isExternal -}} {{- if strings.HasPrefix .Destination "/" -}} {{- with $site.GetPage .Destination -}} {{- $internalPage = . -}} {{- $internalPageFound = true -}} {{- end -}} {{- else if and $path (ne $path "") -}} {{- with $page.GetPage $path -}} {{- $internalPage = . -}} {{- $internalPageFound = true -}} {{- end -}} {{- end -}} {{- if and (not $internalPageFound) $path (ne $path "") -}} {{- with $site.GetPage $path -}} {{- $internalPage = . -}} {{- $internalPageFound = true -}} {{- end -}} {{- end -}} {{- end -}} {{- $report := dict -}} {{- if fileExists "tools/cache/external_links.yaml" -}} {{- $report = transform.Unmarshal (readFile "tools/cache/external_links.yaml") -}} {{- end -}} {{- $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 -}} {{- $deadStatus := "" -}} {{- with (index $deadInfo "status") -}} {{- $deadStatus = printf "%v" . -}} {{- end -}} {{- if eq $deadStatus "" -}} {{- with (index $cacheEntry "status") -}} {{- $deadStatus = printf "%v" . -}} {{- end -}} {{- end -}} {{- $isConfirmedDeadLink := false -}} {{- if and $isDeadLink (eq $deadStatus "404") -}} {{- $isConfirmedDeadLink = true -}} {{- end -}} {{- $titleParts := slice -}} {{- if $isAffiliated -}} {{- $titleParts = $titleParts | append "Lien affiliƩ" -}} {{- else if $isExternal -}} {{- $titleParts = $titleParts | append "Lien externe" -}} {{- end -}} {{- if and (not $isExternal) $internalPageFound -}} {{- $internalTitle := $internalPage.LinkTitle | default $internalPage.Title -}} {{- with $internalPage.Date -}} {{- $internalTitle = printf "%s (%s)" $internalTitle (. | time.Format "02/01/2006") -}} {{- end -}} {{- $titleParts = $titleParts | append $internalTitle -}} {{- else -}} {{- with .Title -}} {{- $titleParts = $titleParts | append . -}} {{- end -}} {{- 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 -}} {{- if gt (len $deadDetails) 0 -}} {{- $titleParts = $titleParts | append (printf "(%s)" (delimit $deadDetails " ; ")) -}} {{- end -}} {{- end -}} {{- $titleValue := delimit $titleParts " - " -}} {{- $linkClasses := slice -}} {{- if $isExternal -}} {{- $linkClasses = $linkClasses | append "link-external" -}} {{- end -}} {{- if $isAffiliated -}} {{- $linkClasses = $linkClasses | append "link-affiliated" -}} {{- end -}} {{- if $isDeadLink -}} {{- $linkClasses = $linkClasses | append "link-dead" -}} {{- if $isConfirmedDeadLink -}} {{- $linkClasses = $linkClasses | append "link-dead-404" -}} {{- end -}} {{- end -}} {{- with $customClass -}} {{- range (split . " ") -}} {{- if ne . "" -}} {{- $linkClasses = $linkClasses | append . -}} {{- end -}} {{- end -}} {{- end -}} {{- $classValue := delimit $linkClasses " " -}} {{- strings.TrimSpace .Text | safeHTML -}}{{- "" -}}