1

Gestion et affichage des liens morts

This commit is contained in:
2025-11-11 17:27:52 +01:00
parent e533dc3fc1
commit 39dbd89397
13 changed files with 892 additions and 1356 deletions

View File

@@ -0,0 +1,82 @@
{{- $defaultReportPath := "tools/cache/external_links.yaml" -}}
{{- $reportPath := default $defaultReportPath .ReportPath -}}
{{- $report := default (dict) .Report -}}
{{- if or (eq (len $report) 0) (not (isset $report "links")) -}}
{{- if fileExists $reportPath -}}
{{- with readFile $reportPath -}}
{{- $report = . | unmarshal -}}
{{- end -}}
{{- else -}}
{{- warnf "Rapport des liens morts introuvable (%s)" $reportPath -}}
{{- end -}}
{{- end -}}
{{- $allPages := where site.Pages ".File" "!=" nil -}}
{{- $links := default (slice) $report.links -}}
{{- $linkCount := len $links -}}
{{- $generatedLabel := "" -}}
{{- with $report.generatedAt -}}
{{- $ts := time . -}}
{{- $generatedLabel = $ts.Format "02/01/2006" -}}
{{- end -}}
<div aria-label="Statistiques" class="stats">
{{ partial "stat.html" (dict "title" "Dernière mise à jour" "value" $generatedLabel)}}
{{ partial "stat.html" (dict "title" "Liens morts détectés" "value" $linkCount)}}
</div>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th>URL</th>
<th>Emplacements</th>
<th>Statut</th>
</tr>
</thead>
<tbody>
{{- range $links }}
<tr>
<td>
<a href="{{ .url }}" rel="noreferrer noopener" target="_blank">{{ .url }}</a>
</td>
<td>
{{- $locations := default (slice) .locations -}}
{{- if gt (len $locations) 0 -}}
{{- range $locations }}
{{- $file := .file -}}
{{- $line := .line -}}
{{- $pagePath := .page -}}
{{- $matchedPage := false -}}
{{- if $pagePath -}}
{{- $candidate := site.GetPage $pagePath -}}
{{- if $candidate -}}
{{- $matchedPage = $candidate -}}
{{- end -}}
{{- end -}}
{{- if and (not $matchedPage) $file -}}
{{- $normalized := replaceRE "^content/" "" $file -}}
{{- $candidates := where $allPages "File.Path" $normalized -}}
{{- if gt (len $candidates) 0 -}}
{{- $matchedPage = index $candidates 0 -}}
{{- end -}}
{{- end -}}
{{- if $matchedPage -}}
<a href="{{ $matchedPage.RelPermalink }}">{{ $matchedPage.Title }}</a>
{{- else if $file -}}
<code>{{ $file }}{{ if $line }}:{{ $line }}{{ end }}</code>
{{- else -}}
<em>Emplacement inconnu</em>
{{- end -}}
<br />
{{- end }}
{{- else -}}
<em>Emplacements inconnus</em>
{{- end -}}
</td>
<td><code>{{ .status }}</code></td>
</tr>
{{- end }}
</tbody>
</table>
</div>
</div>