58 lines
2.0 KiB
HTML
58 lines
2.0 KiB
HTML
{{- $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 -}}
|
|
{{- $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 -}}
|
|
{{- end -}}
|
|
{{- $cacheEntry := index $externalCache .Destination -}}
|
|
{{- $isDeadLink := and $cacheEntry (eq (index $cacheEntry "manually_killed") true) -}}
|
|
{{- $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 := "" -}}
|
|
{{- if $isAffiliated -}}
|
|
{{- $titlePrefix = "Lien affilié" -}}
|
|
{{- else if $isExternal -}}
|
|
{{- $titlePrefix = "Lien externe" -}}
|
|
{{- end -}}
|
|
{{- $classes := slice -}}
|
|
{{- if $isExternal -}}
|
|
{{- $classes = $classes | append "external" -}}
|
|
{{- if $isAffiliated -}}
|
|
{{- $classes = $classes | append "affiliated" -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- if $isDeadLink -}}
|
|
{{- $classes = $classes | append "dead" -}}
|
|
{{- end -}}
|
|
<a href="{{ $newURL }}" title="{{ $titlePrefix }}{{ .Title }}"
|
|
{{- if $isExternal -}} rel="noreferrer"{{- end -}}
|
|
{{- if gt (len $classes) 0 -}} class="{{ delimit $classes " " }}"{{- end -}}>
|
|
{{- .Text | safeHTML -}}
|
|
</a>
|