Nouveau thème pour 2026
This commit is contained in:
115
themes/2026/layouts/_partials/render/link.html
Normal file
115
themes/2026/layouts/_partials/render/link.html
Normal file
@@ -0,0 +1,115 @@
|
||||
{{- $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 -}}
|
||||
{{- $newURL := .Destination -}}
|
||||
{{- $customClass := "" -}}
|
||||
|
||||
{{- if reflect.IsMap . -}}
|
||||
{{- if isset . "Class" -}}
|
||||
{{- with (index . "Class") -}}
|
||||
{{- $customClass = . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and $isExternal $aff -}}
|
||||
{{- $isAffiliated = true -}}
|
||||
{{- if $query -}}
|
||||
{{- $newURL = printf "%s://%s%s?%s&%s=%s" $parsed.Scheme $host $path $query $aff.param $aff.value -}}
|
||||
{{- else -}}
|
||||
{{- $newURL = printf "%s://%s%s?%s=%s" $parsed.Scheme $host $path $aff.param $aff.value -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $internalPage := "" -}}
|
||||
{{- $internalPageFound := false -}}
|
||||
{{- if not $isExternal -}}
|
||||
{{- if strings.HasPrefix .Destination "/" -}}
|
||||
{{- with $site.GetPage .Destination -}}
|
||||
{{- $internalPage = . -}}
|
||||
{{- $internalPageFound = true -}}
|
||||
{{- end -}}
|
||||
{{- else if and $path (ne $path "") -}}
|
||||
{{- with $page.GetPage $path -}}
|
||||
{{- $internalPage = . -}}
|
||||
{{- $internalPageFound = true -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if and (not $internalPageFound) $path (ne $path "") -}}
|
||||
{{- with $site.GetPage $path -}}
|
||||
{{- $internalPage = . -}}
|
||||
{{- $internalPageFound = true -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $report := dict -}}
|
||||
{{- if fileExists "tools/cache/external_links.yaml" -}}
|
||||
{{- $report = transform.Unmarshal (readFile "tools/cache/external_links.yaml") -}}
|
||||
{{- end -}}
|
||||
{{- $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 -}}
|
||||
|
||||
{{- $titleParts := slice -}}
|
||||
{{- if $isAffiliated -}}
|
||||
{{- $titleParts = $titleParts | append "Lien affilié" -}}
|
||||
{{- else if $isExternal -}}
|
||||
{{- $titleParts = $titleParts | append "Lien externe" -}}
|
||||
{{- end -}}
|
||||
{{- if and (not $isExternal) $internalPageFound -}}
|
||||
{{- $internalTitle := $internalPage.LinkTitle | default $internalPage.Title -}}
|
||||
{{- with $internalPage.Date -}}
|
||||
{{- $internalTitle = printf "%s (%s)" $internalTitle (. | time.Format "02/01/2006") -}}
|
||||
{{- end -}}
|
||||
{{- $titleParts = $titleParts | append $internalTitle -}}
|
||||
{{- else -}}
|
||||
{{- with .Title -}}
|
||||
{{- $titleParts = $titleParts | append . -}}
|
||||
{{- end -}}
|
||||
{{- 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 -}}
|
||||
{{- if gt (len $deadDetails) 0 -}}
|
||||
{{- $titleParts = $titleParts | append (printf "(%s)" (delimit $deadDetails " ; ")) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $titleValue := delimit $titleParts " - " -}}
|
||||
{{- $linkClasses := slice -}}
|
||||
{{- if $isExternal -}}
|
||||
{{- $linkClasses = $linkClasses | append "link-external" -}}
|
||||
{{- end -}}
|
||||
{{- if $isAffiliated -}}
|
||||
{{- $linkClasses = $linkClasses | append "link-affiliated" -}}
|
||||
{{- end -}}
|
||||
{{- with $customClass -}}
|
||||
{{- range (split . " ") -}}
|
||||
{{- if ne . "" -}}
|
||||
{{- $linkClasses = $linkClasses | append . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $classValue := delimit $linkClasses " " -}}
|
||||
<a href="{{- $newURL -}}"{{ with $classValue }} class="{{- . -}}"{{ end }}{{ with $titleValue }} title="{{- . -}}"{{ end }}{{ if $isExternal }} rel="noreferrer noopener"{{ end }}>{{- strings.TrimSpace .Text | safeHTML -}}</a>{{- "" -}}
|
||||
Reference in New Issue
Block a user