Gestion et affichage des liens morts
This commit is contained in:
@@ -7,22 +7,16 @@
|
||||
{{- $site := $page.Site -}}
|
||||
{{- $aff := index $site.Data.affiliates.sites $host -}}
|
||||
{{- $isAffiliated := false -}}
|
||||
{{- $scratch := $page.Scratch -}}
|
||||
{{- $externalCache := $scratch.Get "externalLinksCache" -}}
|
||||
{{- if not $externalCache -}}
|
||||
{{- $externalCache = dict -}}
|
||||
{{- if fileExists "tools/cache/external_links.yaml" -}}
|
||||
{{- with readFile "tools/cache/external_links.yaml" -}}
|
||||
{{- $parsedCache := transform.Unmarshal . -}}
|
||||
{{- if $parsedCache -}}
|
||||
{{- $externalCache = $parsedCache -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $scratch.Set "externalLinksCache" $externalCache -}}
|
||||
{{- $report := default (dict) (transform.Unmarshal (readFile "tools/cache/external_links.yaml")) -}}
|
||||
{{- $deadList := default (slice) (index $report "links") -}}
|
||||
{{- $entriesMap := default (dict) (index $report "entries") -}}
|
||||
{{- $cacheEntry := index $entriesMap .Destination -}}
|
||||
{{- $deadInfo := dict -}}
|
||||
{{- $isDeadLink := false -}}
|
||||
{{- with (first 1 (where $deadList "url" .Destination)) -}}
|
||||
{{- $deadInfo = index . 0 -}}
|
||||
{{- $isDeadLink = true -}}
|
||||
{{- end -}}
|
||||
{{- $cacheEntry := index $externalCache .Destination -}}
|
||||
{{- $isDeadLink := and $cacheEntry (eq (index $cacheEntry "manually_killed") true) -}}
|
||||
{{- $newURL := .Destination -}}
|
||||
{{- if and $isExternal $aff -}}
|
||||
{{- $param := $aff.param -}}
|
||||
@@ -34,12 +28,7 @@
|
||||
{{- $newURL = printf "%s://%s%s?%s=%s" $parsed.Scheme $host $path $param $value -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $titlePrefix := "" -}}
|
||||
{{- if $isAffiliated -}}
|
||||
{{- $titlePrefix = "Lien affilié" -}}
|
||||
{{- else if $isExternal -}}
|
||||
{{- $titlePrefix = "Lien externe" -}}
|
||||
{{- end -}}
|
||||
{{- $titlePrefix := cond $isAffiliated "Lien affilié" (cond $isExternal "Lien externe" "") -}}
|
||||
{{- $classes := slice -}}
|
||||
{{- if $isExternal -}}
|
||||
{{- $classes = $classes | append "external" -}}
|
||||
@@ -50,9 +39,32 @@
|
||||
{{- if $isDeadLink -}}
|
||||
{{- $classes = $classes | append "dead" -}}
|
||||
{{- end -}}
|
||||
<a href="{{ $newURL }}" title="{{ $titlePrefix }}{{ .Title }}"
|
||||
{{- $titleParts := slice -}}
|
||||
{{- with $titlePrefix -}}
|
||||
{{- $titleParts = $titleParts | append . -}}
|
||||
{{- end -}}
|
||||
{{- with .Title -}}
|
||||
{{- $titleParts = $titleParts | append . -}}
|
||||
{{- end -}}
|
||||
{{- if $isDeadLink -}}
|
||||
{{- $deadDetails := slice -}}
|
||||
{{- with (index $cacheEntry "checkedAt") -}}
|
||||
{{- $deadDetails = $deadDetails | append (printf "inaccessible depuis le %s" (time.Format "02/01/2006" (time .))) -}}
|
||||
{{- end -}}
|
||||
{{- with (index $cacheEntry "errorType") -}}
|
||||
{{- $deadDetails = $deadDetails | append (printf "raison %s" .) -}}
|
||||
{{- end -}}
|
||||
{{- with (index $deadInfo "status") -}}
|
||||
{{- $deadDetails = $deadDetails | append (printf "statut %v" .) -}}
|
||||
{{- end -}}
|
||||
{{- with $deadDetails -}}
|
||||
{{- $titleParts = $titleParts | append (printf "(%s)" (delimit . " ; ")) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $titleValue := delimit $titleParts " - " -}}
|
||||
<a href="{{ $newURL }}" title="{{ $titleValue }}"
|
||||
{{- if $isExternal -}} rel="noreferrer"{{- end -}}
|
||||
{{- if gt (len $classes) 0 -}} class="{{ delimit $classes ` ` }}"{{- end -}}>
|
||||
{{- .Text | safeHTML -}}
|
||||
</a>
|
||||
{{- /* */ -}}
|
||||
{{- /* */ -}}
|
||||
|
||||
82
themes/42/layouts/_partials/liens-morts/report.html
Normal file
82
themes/42/layouts/_partials/liens-morts/report.html
Normal 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>
|
||||
34
themes/42/layouts/liens-morts/single.html
Normal file
34
themes/42/layouts/liens-morts/single.html
Normal file
@@ -0,0 +1,34 @@
|
||||
{{ define "main" }}
|
||||
{{ partial "hero-page.html" . }}
|
||||
<main>
|
||||
<article class="article-body">
|
||||
|
||||
{{- if eq .Page.Parent.RelPermalink "/interets/liens-interessants/" -}}
|
||||
{{- else -}}
|
||||
{{- if .Params.cover -}}
|
||||
{{- partial "media/render-image.html" (dict
|
||||
"Page" .Page
|
||||
"Destination" .Params.cover
|
||||
) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{ with .TableOfContents }}
|
||||
{{ if gt (len (plainify .)) 0 }}
|
||||
<div class="stat">
|
||||
<strong>
|
||||
Sommaire
|
||||
</strong>
|
||||
{{ . | safeHTML }}
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ .Content }}
|
||||
|
||||
{{- partial "liens-morts/report.html" (dict "Page" .) -}}
|
||||
|
||||
{{- partial "asides/keywords.html" . }}
|
||||
</article>
|
||||
</main>
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user