{{- $destination := .Destination -}} {{- if strings.Contains $destination "~~" -}} {{- $destination = replace $destination "~~" "" -}} {{- end -}} {{- $isExternal := or (strings.HasPrefix $destination "http://") (strings.HasPrefix $destination "https://") -}} {{- $host := "" -}} {{- $path := replaceRE "[?#].*$" "" $destination -}} {{- $query := "" -}} {{- $scheme := "" -}} {{- if and $isExternal (gt (len (findRE "^https?://[^[:space:]]+$" $destination 1)) 0) -}} {{- $parsed := urls.Parse $destination -}} {{- $host = $parsed.Host -}} {{- $path = $parsed.Path -}} {{- $query = $parsed.RawQuery -}} {{- $scheme = $parsed.Scheme -}} {{- end -}} {{- $page := .Page -}} {{- $site := $page.Site -}} {{- $deletions := partialCached "deletions-lookup.html" (dict) "default" -}} {{- $replacements := default (dict) $site.Data.replacements -}} {{- $aff := index $site.Data.affiliates.sites $host -}} {{- $isAffiliated := false -}} {{- $newURL := $destination -}} {{- $lookupURLs := slice $destination -}} {{- with $destination -}} {{- if strings.HasSuffix . "/" -}} {{- $withoutSlash := strings.TrimSuffix "/" . -}} {{- if ne $withoutSlash . -}} {{- $lookupURLs = $lookupURLs | append $withoutSlash -}} {{- end -}} {{- else -}} {{- $lookupURLs = $lookupURLs | append (printf "%s/" .) -}} {{- end -}} {{- end -}} {{- $isDeleted := false -}} {{- range $lookupURLs -}} {{- if and (not $isDeleted) (isset $deletions .) -}} {{- $isDeleted = true -}} {{- end -}} {{- end -}} {{- $replacementURL := "" -}} {{- $hasReplacement := false -}} {{- if not $isDeleted -}} {{- range $lookupURLs -}} {{- if not $hasReplacement -}} {{- $candidateReplacementURL := index $replacements . -}} {{- if ne $candidateReplacementURL nil -}} {{- $replacementURL = $candidateReplacementURL -}} {{- $hasReplacement = true -}} {{- end -}} {{- end -}} {{- end -}} {{- end -}} {{- $customClass := "" -}} {{- if reflect.IsMap . -}} {{- if isset . "Class" -}} {{- with (index . "Class") -}} {{- $customClass = . -}} {{- end -}} {{- end -}} {{- end -}} {{- if $hasReplacement -}} {{- $newURL = printf "%v" $replacementURL -}} {{- else if and $isExternal $aff -}} {{- $isAffiliated = true -}} {{- if $query -}} {{- $newURL = printf "%s://%s%s?%s&%s=%s" $scheme $host $path $query $aff.param $aff.value -}} {{- else -}} {{- $newURL = printf "%s://%s%s?%s=%s" $scheme $host $path $aff.param $aff.value -}} {{- end -}} {{- end -}} {{- $newHost := "" -}} {{- if and $isExternal (gt (len (findRE "^https?://[^[:space:]]+$" $newURL 1)) 0) -}} {{- $newParsed := urls.Parse $newURL -}} {{- $newHost = lower $newParsed.Host -}} {{- end -}} {{- $isArchiveLink := false -}} {{- if and $isExternal (ne $newHost "") -}} {{- if or (eq $newHost "archive.org") (strings.HasSuffix $newHost ".archive.org") -}} {{- $isArchiveLink = true -}} {{- 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 := partialCached "external-links-report.html" (dict) "default" -}} {{- $entriesMap := default (dict) (index $report "entries") -}} {{- $deadLinksMap := default (dict) (index $report "linksMap") -}} {{- $cacheEntry := dict -}} {{- range $lookupURLs -}} {{- if and (eq (len $cacheEntry) 0) (isset $entriesMap .) -}} {{- $cacheEntry = index $entriesMap . -}} {{- end -}} {{- end -}} {{- $deadInfo := dict -}} {{- $isDeadLink := false -}} {{- range $lookupURLs -}} {{- if and (not $isDeadLink) (isset $deadLinksMap .) -}} {{- $deadInfo = index $deadLinksMap . -}} {{- $isDeadLink = true -}} {{- end -}} {{- 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 -}} {{- $isMarkedDeadLink := false -}} {{- with (index $deadInfo "manualMarked") -}} {{- $isMarkedDeadLink = . -}} {{- end -}} {{- if not $isMarkedDeadLink -}} {{- with (index $cacheEntry "manualMarked") -}} {{- $isMarkedDeadLink = . -}} {{- end -}} {{- end -}} {{- $titleParts := slice -}} {{- if $isAffiliated -}} {{- $titleParts = $titleParts | append "Lien affilié" -}} {{- else if $isExternal -}} {{- $titleParts = $titleParts | append "Lien externe" -}} {{- end -}} {{- if $isArchiveLink -}} {{- $titleParts = $titleParts | append "Internet Archive" -}} {{- 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 -}} {{- if $isMarkedDeadLink -}} {{- $deadDetails = $deadDetails | append "supprimé" -}} {{- end -}} {{- 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") -}} {{- $statusLabel := printf "%v" . -}} {{- if not (and $isMarkedDeadLink (or (eq $statusLabel "manual") (eq $statusLabel "deleted"))) -}} {{- $deadDetails = $deadDetails | append (printf "statut %s" $statusLabel) -}} {{- end -}} {{- end -}} {{- if gt (len $deadDetails) 0 -}} {{- $titleParts = $titleParts | append (printf "(%s)" (delimit $deadDetails " ; ")) -}} {{- end -}} {{- end -}} {{- $titleValue := delimit $titleParts " - " -}} {{- if $hasReplacement -}} {{- $titleValue = printf "Page d'origine : %s" $destination -}} {{- end -}} {{- $linkClasses := slice -}} {{- if $isExternal -}} {{- $linkClasses = $linkClasses | append "link-external" -}} {{- end -}} {{- if $isAffiliated -}} {{- $linkClasses = $linkClasses | append "link-affiliated" -}} {{- end -}} {{- if $isArchiveLink -}} {{- $linkClasses = $linkClasses | append "link-archive" -}} {{- end -}} {{- if $isDeadLink -}} {{- $linkClasses = $linkClasses | append "link-dead" -}} {{- if $isConfirmedDeadLink -}} {{- $linkClasses = $linkClasses | append "link-dead-404" -}} {{- end -}} {{- if $isMarkedDeadLink -}} {{- $linkClasses = $linkClasses | append "link-dead-marked" -}} {{- end -}} {{- end -}} {{- with $customClass -}} {{- range (split . " ") -}} {{- if ne . "" -}} {{- $linkClasses = $linkClasses | append . -}} {{- end -}} {{- end -}} {{- end -}} {{- $classValue := delimit $linkClasses " " -}} {{- if $isMarkedDeadLink -}} {{- $deadTitleValue := printf "URL d'origine : %s" $destination -}} {{- $deadAriaLabel := printf "Lien supprimé. URL d'origine : %s" $destination -}} {{- strings.TrimSpace .Text | safeHTML -}} {{- else -}} {{- strings.TrimSpace .Text | safeHTML -}} {{- end -}}{{- "" -}}