1

Correction des liens morts

This commit is contained in:
2026-03-28 16:09:04 +01:00
parent 44dc63bebf
commit 7452eb0876
17 changed files with 372 additions and 360 deletions

View File

@@ -1,11 +1,11 @@
{{- $url := "" -}}
{{- $report := dict -}}
{{- $report := partial "external-links-report.html" (dict) -}}
{{- if reflect.IsMap . -}}
{{- with index . "URL" -}}
{{- $url = . -}}
{{- end -}}
{{- with index . "Report" -}}
{{- $report = . -}}
{{- $report = partial "external-links-report.html" (dict "Report" .) -}}
{{- end -}}
{{- end -}}
@@ -89,6 +89,12 @@
{{- end -}}
{{- end -}}
{{- if and (eq $statusChecked "") (gt (len $deadInfo) 0) -}}
{{- with index $deadInfo "checkedAt" -}}
{{- $statusChecked = . -}}
{{- end -}}
{{- end -}}
{{- if gt $statusCode 0 -}}
{{- if lt $statusCode 400 -}}
{{- $statusTone = "ok" -}}

View File

@@ -0,0 +1,58 @@
{{- $reportPath := "data/external_links.yaml" -}}
{{- $report := dict -}}
{{- if reflect.IsMap . -}}
{{- with index . "ReportPath" -}}
{{- $reportPath = . -}}
{{- end -}}
{{- with index . "Report" -}}
{{- $report = . -}}
{{- end -}}
{{- else if . -}}
{{- $report = . -}}
{{- end -}}
{{- if eq (len $report) 0 -}}
{{- if eq $reportPath "data/external_links.yaml" -}}
{{- with index site.Data "external_links" -}}
{{- $report = . -}}
{{- end -}}
{{- else if fileExists $reportPath -}}
{{- $report = transform.Unmarshal (readFile $reportPath) -}}
{{- end -}}
{{- end -}}
{{- $sourceLinks := slice -}}
{{- with index $report "deadLinks" -}}
{{- $sourceLinks = . -}}
{{- end -}}
{{- if and (eq (len $sourceLinks) 0) (isset $report "links") -}}
{{- $sourceLinks = default (slice) (index $report "links") -}}
{{- end -}}
{{- $links := slice -}}
{{- range $sourceLinks -}}
{{- $status := "" -}}
{{- with index . "status" -}}
{{- $status = printf "%v" . -}}
{{- end -}}
{{- if eq $status "" -}}
{{- with index . "code" -}}
{{- $status = printf "%v" . -}}
{{- end -}}
{{- end -}}
{{- $links = $links | append (dict
"url" (default "" (index . "url"))
"status" $status
"locations" (default (slice) (index . "locations"))
"errorType" (default "" (index . "errorType"))
"checkedAt" (default "" (index . "checkedAt"))
) -}}
{{- end -}}
{{- return (dict
"generatedAt" (default "" (index $report "generatedAt"))
"entries" (default (dict) (index $report "entries"))
"links" $links
) -}}

View File

@@ -1,14 +1,4 @@
{{- $defaultReportPath := "data/external_links.yaml" -}}
{{- $reportPath := default $defaultReportPath .ReportPath -}}
{{- $report := default (dict) .Report -}}
{{- if or (eq (len $report) 0) (not (isset $report "links")) -}}
{{- if fileExists $reportPath -}}
{{- $report = transform.Unmarshal (readFile $reportPath) -}}
{{- else -}}
{{- warnf "Rapport des liens morts introuvable (%s)" $reportPath -}}
{{- end -}}
{{- end -}}
{{- $report := partial "external-links-report.html" . -}}
{{- $allPages := where site.Pages ".File" "!=" nil -}}
{{- $links := default (slice) $report.links -}}
{{- $generatedLabel := "" -}}
@@ -39,9 +29,22 @@
{{- $locations := default (slice) .locations -}}
{{- if gt (len $locations) 0 -}}
{{- range $locations -}}
{{- $file := .file -}}
{{- $line := .line -}}
{{- $pagePath := .page -}}
{{- $file := "" -}}
{{- $line := "" -}}
{{- $pagePath := "" -}}
{{- if reflect.IsMap . -}}
{{- with index . "file" -}}
{{- $file = printf "%v" . -}}
{{- end -}}
{{- with index . "line" -}}
{{- $line = printf "%v" . -}}
{{- end -}}
{{- with index . "page" -}}
{{- $pagePath = printf "%v" . -}}
{{- end -}}
{{- else -}}
{{- $pagePath = printf "%v" . -}}
{{- end -}}
{{- $matchedPage := false -}}
{{- if $pagePath -}}
{{- $candidate := site.GetPage $pagePath -}}
@@ -60,6 +63,8 @@
<a href="{{ $matchedPage.RelPermalink }}">{{ $matchedPage.Title }}</a>
{{- else if $file -}}
<code>{{ $file }}{{ if $line }}:{{ $line }}{{ end }}</code>
{{- else if $pagePath -}}
<code>{{ $pagePath }}</code>
{{- else -}}
<em>Emplacement inconnu</em>
{{- end -}}

View File

@@ -5,10 +5,7 @@
{{- $excludeInterestingLinks := false -}}
{{- $groupBySubSections := false -}}
{{- $subSections := slice -}}
{{- $externalLinksReport := dict -}}
{{- if fileExists "tools/cache/external_links.yaml" -}}
{{- $externalLinksReport = transform.Unmarshal (readFile "tools/cache/external_links.yaml") -}}
{{- end -}}
{{- $externalLinksReport := partial "external-links-report.html" (dict) -}}
{{- with $context -}}
{{- if eq (strings.TrimSuffix "/" .RelPermalink) "/interets" -}}
{{- $excludeInterestingLinks = true -}}

View File

@@ -49,10 +49,7 @@
{{- end -}}
{{- end -}}
{{- $report := dict -}}
{{- if fileExists "tools/cache/external_links.yaml" -}}
{{- $report = transform.Unmarshal (readFile "tools/cache/external_links.yaml") -}}
{{- end -}}
{{- $report := partial "external-links-report.html" (dict) -}}
{{- $deadList := default (slice) (index $report "links") -}}
{{- $entriesMap := default (dict) (index $report "entries") -}}
{{- $cacheEntry := index $entriesMap .Destination -}}