Correction de liens morts
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
{{- $report := partial "external-links-report.html" . -}}
|
||||
{{- $allPages := where site.Pages ".File" "!=" nil -}}
|
||||
{{- $links := default (slice) $report.links -}}
|
||||
{{- $replacements := default (dict) site.Data.replacements -}}
|
||||
{{- $sourceLinks := default (slice) $report.links -}}
|
||||
{{- $links := slice -}}
|
||||
{{- range $sourceLinks -}}
|
||||
{{- if eq (index $replacements .url) nil -}}
|
||||
{{- $links = $links | append . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $generatedLabel := "" -}}
|
||||
{{- with $report.generatedAt -}}
|
||||
{{- $generatedLabel = (time .).Format "02/01/2006" -}}
|
||||
|
||||
@@ -1,13 +1,28 @@
|
||||
{{- $isExternal := strings.HasPrefix .Destination "http" -}}
|
||||
{{- $parsed := urls.Parse .Destination -}}
|
||||
{{- $host := $parsed.Host -}}
|
||||
{{- $path := $parsed.Path -}}
|
||||
{{- $query := $parsed.RawQuery -}}
|
||||
{{- $destination := .Destination -}}
|
||||
{{- if hasPrefix $destination "~~" -}}
|
||||
{{- $destination = replaceRE "^~~" "" $destination -}}
|
||||
{{- $destination = replaceRE "~~([/?#]|$)" "$1" $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 -}}
|
||||
{{- $replacements := default (dict) $site.Data.replacements -}}
|
||||
{{- $aff := index $site.Data.affiliates.sites $host -}}
|
||||
{{- $isAffiliated := false -}}
|
||||
{{- $newURL := .Destination -}}
|
||||
{{- $newURL := $destination -}}
|
||||
{{- $replacementURL := index $replacements $destination -}}
|
||||
{{- $hasReplacement := ne $replacementURL nil -}}
|
||||
{{- $customClass := "" -}}
|
||||
|
||||
{{- if reflect.IsMap . -}}
|
||||
@@ -18,20 +33,22 @@
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and $isExternal $aff -}}
|
||||
{{- if $hasReplacement -}}
|
||||
{{- $newURL = printf "%v" $replacementURL -}}
|
||||
{{- else 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 -}}
|
||||
{{- $newURL = printf "%s://%s%s?%s&%s=%s" $scheme $host $path $query $aff.param $aff.value -}}
|
||||
{{- else -}}
|
||||
{{- $newURL = printf "%s://%s%s?%s=%s" $parsed.Scheme $host $path $aff.param $aff.value -}}
|
||||
{{- $newURL = printf "%s://%s%s?%s=%s" $scheme $host $path $aff.param $aff.value -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $internalPage := "" -}}
|
||||
{{- $internalPageFound := false -}}
|
||||
{{- if not $isExternal -}}
|
||||
{{- if strings.HasPrefix .Destination "/" -}}
|
||||
{{- with $site.GetPage .Destination -}}
|
||||
{{- if strings.HasPrefix $destination "/" -}}
|
||||
{{- with $site.GetPage $destination -}}
|
||||
{{- $internalPage = . -}}
|
||||
{{- $internalPageFound = true -}}
|
||||
{{- end -}}
|
||||
@@ -52,10 +69,10 @@
|
||||
{{- $report := partial "external-links-report.html" (dict) -}}
|
||||
{{- $deadList := default (slice) (index $report "links") -}}
|
||||
{{- $entriesMap := default (dict) (index $report "entries") -}}
|
||||
{{- $cacheEntry := index $entriesMap .Destination -}}
|
||||
{{- $cacheEntry := index $entriesMap $destination -}}
|
||||
{{- $deadInfo := dict -}}
|
||||
{{- $isDeadLink := false -}}
|
||||
{{- with (first 1 (where $deadList "url" .Destination)) -}}
|
||||
{{- with (first 1 (where $deadList "url" $destination)) -}}
|
||||
{{- $deadInfo = index . 0 -}}
|
||||
{{- $isDeadLink = true -}}
|
||||
{{- end -}}
|
||||
@@ -107,6 +124,9 @@
|
||||
{{- end -}}
|
||||
|
||||
{{- $titleValue := delimit $titleParts " - " -}}
|
||||
{{- if $hasReplacement -}}
|
||||
{{- $titleValue = printf "Page d'origine : %s" $destination -}}
|
||||
{{- end -}}
|
||||
{{- $linkClasses := slice -}}
|
||||
{{- if $isExternal -}}
|
||||
{{- $linkClasses = $linkClasses | append "link-external" -}}
|
||||
|
||||
Reference in New Issue
Block a user