1

Sécuriser et documenter les liens morts

Rend les liens supprimés non cliquables, améliore le rapport des liens morts et accélère la génération du site.

Closes #2
Closes #3
Closes #4
This commit is contained in:
2026-04-02 22:23:16 +02:00
parent 0e4e8cd076
commit fe8037bb73
40 changed files with 423 additions and 112 deletions

View File

@@ -0,0 +1,9 @@
{{- $deletionsList := default (slice) site.Data.deletions -}}
{{- $deletions := dict -}}
{{- range $deletionsList -}}
{{- $deletedURL := strings.TrimSpace (printf "%v" .) -}}
{{- if ne $deletedURL "" -}}
{{- $deletions = merge $deletions (dict $deletedURL true) -}}
{{- end -}}
{{- end -}}
{{- return $deletions -}}

View File

@@ -1,5 +1,6 @@
{{- $reportPath := "data/external_links.yaml" -}}
{{- $report := dict -}}
{{- $withLocations := false -}}
{{- if reflect.IsMap . -}}
{{- with index . "ReportPath" -}}
@@ -8,6 +9,9 @@
{{- with index . "Report" -}}
{{- $report = . -}}
{{- end -}}
{{- with index . "WithLocations" -}}
{{- $withLocations = . -}}
{{- end -}}
{{- else if . -}}
{{- $report = . -}}
{{- end -}}
@@ -30,7 +34,10 @@
{{- $sourceLinks = default (slice) (index $report "links") -}}
{{- end -}}
{{- $links := slice -}}
{{- $entries := default (dict) (index $report "entries") -}}
{{- $deletions := partialCached "deletions-lookup.html" (dict) "default" -}}
{{- $linksByURL := dict -}}
{{- range $sourceLinks -}}
{{- $code := "" -}}
{{- if isset . "code" -}}
@@ -55,20 +62,100 @@
{{- if and (eq $status "") (ne $statusText "") -}}
{{- $status = $statusText -}}
{{- end -}}
{{- $links = $links | append (dict
"url" (default "" (index . "url"))
{{- $url := strings.TrimSpace (printf "%v" (default "" (index . "url"))) -}}
{{- $linksByURL = merge $linksByURL (dict $url (dict
"url" $url
"code" $code
"statusText" $statusText
"status" $status
"locations" (default (slice) (index . "locations"))
"errorType" (default "" (index . "errorType"))
"checkedAt" (default "" (index . "checkedAt"))
) -}}
"manualMarked" false
)) -}}
{{- end -}}
{{- range $url, $_ := $deletions -}}
{{- $existingLink := default (dict) (index $linksByURL $url) -}}
{{- $locations := default (slice) (index $existingLink "locations") -}}
{{- if $withLocations -}}
{{- $locations = slice -}}
{{- end -}}
{{- $linksByURL = merge $linksByURL (dict $url (merge $existingLink (dict
"url" $url
"status" "deleted"
"statusText" "Supprimé"
"locations" $locations
"manualMarked" true
))) -}}
{{- $existingEntry := default (dict) (index $entries $url) -}}
{{- $entries = merge $entries (dict $url (merge $existingEntry (dict
"status" "deleted"
"statusText" "Supprimé"
"manualMarked" true
))) -}}
{{- end -}}
{{- if $withLocations -}}
{{- range where site.RegularPages ".File" "!=" nil -}}
{{- $page := . -}}
{{- $pageLocation := dict
"file" (printf "content/%s" $page.File.Path)
"page" $page.Path
-}}
{{- $rawContent := "" -}}
{{- with $page.RawContent -}}
{{- $rawContent = . -}}
{{- end -}}
{{- if ne $rawContent "" -}}
{{- range $url, $_ := $deletions -}}
{{- if strings.Contains $rawContent $url -}}
{{- $existingLink := default (dict) (index $linksByURL $url) -}}
{{- $locations := default (slice) (index $existingLink "locations") -}}
{{- if eq (len (where $locations "file" $pageLocation.file)) 0 -}}
{{- $locations = $locations | append $pageLocation -}}
{{- $linksByURL = merge $linksByURL (dict $url (merge $existingLink (dict "locations" $locations))) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $dataResources := $page.Resources.Match "data/**/*.yaml" | default (slice) -}}
{{- range ($page.Resources.Match "data/**/*.yml" | default (slice)) -}}
{{- $dataResources = $dataResources | append . -}}
{{- end -}}
{{- range $dataResources -}}
{{- $resourceContent := strings.TrimSpace .Content -}}
{{- if ne $resourceContent "" -}}
{{- $resourceLocation := dict
"file" (printf "content/%s/%s" (path.Dir $page.File.Path) .Name)
"page" $page.Path
-}}
{{- range $url, $_ := $deletions -}}
{{- if strings.Contains $resourceContent $url -}}
{{- $existingLink := default (dict) (index $linksByURL $url) -}}
{{- $locations := default (slice) (index $existingLink "locations") -}}
{{- if eq (len (where $locations "file" $resourceLocation.file)) 0 -}}
{{- $locations = $locations | append $resourceLocation -}}
{{- $linksByURL = merge $linksByURL (dict $url (merge $existingLink (dict "locations" $locations))) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $links := slice -}}
{{- range $url, $link := $linksByURL -}}
{{- $links = $links | append $link -}}
{{- end -}}
{{- $links = sort $links "url" -}}
{{- return (dict
"generatedAt" (default "" (index $report "generatedAt"))
"entries" (default (dict) (index $report "entries"))
"entries" $entries
"links" $links
"linksMap" $linksByURL
) -}}