1
Files
2025/themes/2026/layouts/_partials/liens-morts/report.html
2026-02-21 01:50:39 +01:00

77 lines
2.4 KiB
HTML

{{- $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 -}}
{{- $report = transform.Unmarshal (readFile $reportPath) -}}
{{- else -}}
{{- warnf "Rapport des liens morts introuvable (%s)" $reportPath -}}
{{- end -}}
{{- end -}}
{{- $allPages := where site.Pages ".File" "!=" nil -}}
{{- $links := default (slice) $report.links -}}
{{- $generatedLabel := "" -}}
{{- with $report.generatedAt -}}
{{- $generatedLabel = (time .).Format "02/01/2006" -}}
{{- end -}}
<dl>
<dt>Dernière mise à jour</dt>
<dd>{{ $generatedLabel }}</dd>
<dt>Liens morts détectés</dt>
<dd>{{ len $links }}</dd>
</dl>
<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>