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:
@@ -1,13 +1,18 @@
|
||||
{{- $report := partial "external-links-report.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 -}}
|
||||
{{- if eq (index $replacements .url) nil -}}
|
||||
{{- $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" -}}
|
||||
@@ -33,7 +38,13 @@
|
||||
{{- 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 := "" -}}
|
||||
@@ -66,22 +77,41 @@
|
||||
{{- $matchedPage = index $candidates 0 -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $locationKey := "unknown" -}}
|
||||
{{- if $matchedPage -}}
|
||||
<a href="{{ $matchedPage.RelPermalink }}">{{ $matchedPage.Title }}</a>
|
||||
{{- $locationKey = printf "page:%s" $matchedPage.Path -}}
|
||||
{{- else if $file -}}
|
||||
<code>{{ $file }}{{ if $line }}:{{ $line }}{{ end }}</code>
|
||||
{{- $locationKey = printf "file:%s" $file -}}
|
||||
{{- else if $pagePath -}}
|
||||
<code>{{ $pagePath }}</code>
|
||||
{{- else -}}
|
||||
<em>Emplacement inconnu</em>
|
||||
{{- $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 -}}
|
||||
<br>
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- end -}}
|
||||
{{- if not $hasRenderedLocation -}}
|
||||
<em>Emplacements inconnus</em>
|
||||
{{- end -}}
|
||||
</td>
|
||||
<td><a href="{{ .url }}" rel="noreferrer noopener" target="_blank">{{ .url }}</a></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>
|
||||
|
||||
Reference in New Issue
Block a user