28 lines
1.0 KiB
HTML
28 lines
1.0 KiB
HTML
{{- $isExternal := strings.HasPrefix .Destination "http" -}}
|
|
{{- $parsed := urls.Parse .Destination -}}
|
|
{{- $host := $parsed.Host -}}
|
|
{{- $path := $parsed.Path -}}
|
|
{{- $query := $parsed.RawQuery -}}
|
|
{{- $aff := index site.Data.affiliates.sites $host -}}
|
|
{{- $isAffiliated := false -}}
|
|
{{- $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 -}}
|
|
<a href="{{ $newURL }}" title="{{ $titlePrefix }}{{ .Title }}"
|
|
{{- if $isExternal -}} rel="noreferrer" class="external{{ if $isAffiliated }} affiliated{{ end }}" {{- end -}}>
|
|
{{- .Text | safeHTML -}}
|
|
</a> |