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
121 lines
4.4 KiB
HTML
121 lines
4.4 KiB
HTML
{{- $report := partialCached "external-links-report.html" (dict "WithLocations" true) "with-locations" -}}
|
|
{{- $allPages := where site.Pages ".File" "!=" nil -}}
|
|
{{- $replacements := default (dict) site.Data.replacements -}}
|
|
{{- $sourceLinks := default (slice) $report.links -}}
|
|
{{- $links := slice -}}
|
|
{{- range $sourceLinks -}}
|
|
{{- $manualMarked := false -}}
|
|
{{- with index . "manualMarked" -}}
|
|
{{- $manualMarked = . -}}
|
|
{{- end -}}
|
|
{{- if or $manualMarked (eq (index $replacements .url) nil) -}}
|
|
{{- $links = $links | append . -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- $links = sort $links "url" -}}
|
|
{{- $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>Emplacements</th>
|
|
<th>URL</th>
|
|
<th>Code</th>
|
|
<th>Détails</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{{- range $links -}}
|
|
<tr>
|
|
<td>
|
|
{{- $manualMarked := false -}}
|
|
{{- with index . "manualMarked" -}}
|
|
{{- $manualMarked = . -}}
|
|
{{- end -}}
|
|
{{- $locations := default (slice) .locations -}}
|
|
{{- $seenLocations := dict -}}
|
|
{{- $hasRenderedLocation := false -}}
|
|
{{- if gt (len $locations) 0 -}}
|
|
{{- range $locations -}}
|
|
{{- $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 -}}
|
|
{{- 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 -}}
|
|
{{- $locationKey := "unknown" -}}
|
|
{{- if $matchedPage -}}
|
|
{{- $locationKey = printf "page:%s" $matchedPage.Path -}}
|
|
{{- else if $file -}}
|
|
{{- $locationKey = printf "file:%s" $file -}}
|
|
{{- else if $pagePath -}}
|
|
{{- $locationKey = printf "path:%s" $pagePath -}}
|
|
{{- end -}}
|
|
{{- if not (isset $seenLocations $locationKey) -}}
|
|
{{- $seenLocations = merge $seenLocations (dict $locationKey true) -}}
|
|
{{- $hasRenderedLocation = true -}}
|
|
{{- if $matchedPage -}}
|
|
<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 -}}
|
|
<br>
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- if not $hasRenderedLocation -}}
|
|
<em>Emplacements inconnus</em>
|
|
{{- end -}}
|
|
</td>
|
|
<td>
|
|
{{- if $manualMarked -}}
|
|
<del class="link-dead link-dead-marked"><span class="link-dead link-dead-marked" title="URL d'origine : {{ .url }}" aria-label="Lien supprimé. URL d'origine : {{ .url }}">{{ .url }}</span></del>
|
|
{{- else -}}
|
|
<span class="link-dead{{ if eq (printf "%v" .status) "404" }} link-dead-404{{ end }}" title="URL d'origine : {{ .url }}" aria-label="Lien mort. URL d'origine : {{ .url }}">{{ .url }}</span>
|
|
{{- end -}}
|
|
</td>
|
|
<td>{{ with .code }}<code>{{ . }}</code>{{ end }}</td>
|
|
<td>{{ with .statusText }}<code>{{ . }}</code>{{ end }}</td>
|
|
</tr>
|
|
{{- end -}}
|
|
</tbody>
|
|
</table>
|