Création d'un partial pour les liens
This commit is contained in:
@@ -20,4 +20,12 @@
|
|||||||
&:hover {
|
&:hover {
|
||||||
color: var(--color-link-dead-hover);
|
color: var(--color-link-dead-hover);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.problematic {
|
||||||
|
color: var(--color-link-problematic);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: var(--color-link-dead-problematic);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,70 +1 @@
|
|||||||
{{- $isExternal := strings.HasPrefix .Destination "http" -}}
|
{{- partial "render/link.html" . -}}
|
||||||
{{- $parsed := urls.Parse .Destination -}}
|
|
||||||
{{- $host := $parsed.Host -}}
|
|
||||||
{{- $path := $parsed.Path -}}
|
|
||||||
{{- $query := $parsed.RawQuery -}}
|
|
||||||
{{- $page := .Page -}}
|
|
||||||
{{- $site := $page.Site -}}
|
|
||||||
{{- $aff := index $site.Data.affiliates.sites $host -}}
|
|
||||||
{{- $isAffiliated := false -}}
|
|
||||||
{{- $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 -}}
|
|
||||||
{{- $newURL := .Destination -}}
|
|
||||||
{{- if and $isExternal $aff -}}
|
|
||||||
{{- $param := $aff.param -}}
|
|
||||||
{{- $value := $aff.value -}}
|
|
||||||
{{- $isAffiliated = true -}}
|
|
||||||
{{- if $query -}}
|
|
||||||
{{- $newURL = printf "%s://%s%s?%s&%s=%s" $parsed.Scheme $host $path $query $param $value -}}
|
|
||||||
{{- else -}}
|
|
||||||
{{- $newURL = printf "%s://%s%s?%s=%s" $parsed.Scheme $host $path $param $value -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- $titlePrefix := cond $isAffiliated "Lien affilié" (cond $isExternal "Lien externe" "") -}}
|
|
||||||
{{- $classes := slice -}}
|
|
||||||
{{- if $isExternal -}}
|
|
||||||
{{- $classes = $classes | append "external" -}}
|
|
||||||
{{- if $isAffiliated -}}
|
|
||||||
{{- $classes = $classes | append "affiliated" -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- if $isDeadLink -}}
|
|
||||||
{{- $classes = $classes | append "dead" -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- $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>
|
|
||||||
{{- /* */ -}}
|
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
{{ if .Params.links }}
|
{{- $page := . -}}
|
||||||
|
{{- with .Params.links }}
|
||||||
<nav id="page-links">
|
<nav id="page-links">
|
||||||
{{ range .Params.links }}
|
{{- range . }}
|
||||||
<a href="{{ .url }}" rel="noopener noreferer norelated">{{ .name }}</a>
|
{{- $text := default .name .text -}}
|
||||||
{{ end }}
|
{{- $title := default $text .title -}}
|
||||||
|
{{- partial "render/link.html" (dict
|
||||||
|
"Destination" .url
|
||||||
|
"Title" $title
|
||||||
|
"Text" $text
|
||||||
|
"Page" $page
|
||||||
|
) -}}
|
||||||
|
{{- end }}
|
||||||
</nav>
|
</nav>
|
||||||
{{ end }}
|
{{- end }}
|
||||||
|
|||||||
85
themes/42/layouts/_partials/render/link.html
Normal file
85
themes/42/layouts/_partials/render/link.html
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
{{- $isExternal := strings.HasPrefix .Destination "http" -}}
|
||||||
|
{{- $parsed := urls.Parse .Destination -}}
|
||||||
|
{{- $host := $parsed.Host -}}
|
||||||
|
{{- $path := $parsed.Path -}}
|
||||||
|
{{- $query := $parsed.RawQuery -}}
|
||||||
|
{{- $page := .Page -}}
|
||||||
|
{{- $site := $page.Site -}}
|
||||||
|
{{- $aff := index $site.Data.affiliates.sites $host -}}
|
||||||
|
{{- $isAffiliated := false -}}
|
||||||
|
{{- $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 -}}
|
||||||
|
{{- $newURL := .Destination -}}
|
||||||
|
{{- if and $isExternal $aff -}}
|
||||||
|
{{- $param := $aff.param -}}
|
||||||
|
{{- $value := $aff.value -}}
|
||||||
|
{{- $isAffiliated = true -}}
|
||||||
|
{{- if $query -}}
|
||||||
|
{{- $newURL = printf "%s://%s%s?%s&%s=%s" $parsed.Scheme $host $path $query $param $value -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- $newURL = printf "%s://%s%s?%s=%s" $parsed.Scheme $host $path $param $value -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- $titlePrefix := cond $isAffiliated "Lien affilié" (cond $isExternal "Lien externe" "") -}}
|
||||||
|
{{- $classes := slice -}}
|
||||||
|
{{- if $isExternal -}}
|
||||||
|
{{- $classes = $classes | append "external" -}}
|
||||||
|
{{- if $isAffiliated -}}
|
||||||
|
{{- $classes = $classes | append "affiliated" -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- if $isDeadLink -}}
|
||||||
|
{{- $statusRaw := index $deadInfo "status" -}}
|
||||||
|
{{- $statusCode := "" -}}
|
||||||
|
{{- with $statusRaw -}}
|
||||||
|
{{- $statusCode = printf "%v" . -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- if eq $statusCode "404" -}}
|
||||||
|
{{- $classes = $classes | append "dead" -}}
|
||||||
|
{{- else if gt (len $statusCode) 0 -}}
|
||||||
|
{{- $classes = $classes | append "problematic" -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- $classes = $classes | append "dead" -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- $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 " - " -}}
|
||||||
|
{{- $relAttr := "" -}}
|
||||||
|
{{- if $isExternal -}}
|
||||||
|
{{- $relAttr = "noreferrer noopener" -}}
|
||||||
|
{{- end -}}
|
||||||
|
<a href="{{ $newURL }}" title="{{ $titleValue }}"
|
||||||
|
{{- if gt (len $relAttr) 0 -}} rel="{{ $relAttr }}"{{- end -}}
|
||||||
|
{{- if gt (len $classes) 0 -}} class="{{ delimit $classes ` ` }}"{{- end -}}>
|
||||||
|
{{- .Text | safeHTML -}}
|
||||||
|
</a>
|
||||||
|
{{- /* */ -}}
|
||||||
@@ -23,6 +23,8 @@
|
|||||||
--color-link-affiliated-hover: var(--pink-300);
|
--color-link-affiliated-hover: var(--pink-300);
|
||||||
--color-link-dead: var(--red-500);
|
--color-link-dead: var(--red-500);
|
||||||
--color-link-dead-hover: var(--red-300);
|
--color-link-dead-hover: var(--red-300);
|
||||||
|
--color-link-problematic: var(--amber-500);
|
||||||
|
--color-link-problematic-hover: var(--amber-300);
|
||||||
--color-keyword: var(--gray-500);
|
--color-keyword: var(--gray-500);
|
||||||
--color-keyword-hover: var(--gray-0);
|
--color-keyword-hover: var(--gray-0);
|
||||||
--color-footer-link: var(--gray-500);
|
--color-footer-link: var(--gray-500);
|
||||||
|
|||||||
Reference in New Issue
Block a user