2020-11-23 11:31:02 +01:00
|
|
|
{{/*
|
|
|
|
S'il n'y a pas de / dans l'url d'un lien alors on ajoute le path du répertoire
|
|
|
|
*/}}
|
|
|
|
{{ $isExternalLink := strings.HasPrefix .Destination "http" }}
|
2020-12-03 16:58:35 +01:00
|
|
|
{{ $isWebLink := or $isExternalLink (eq 0 (.Destination | strings.Count ":")) }}
|
2020-11-23 11:31:02 +01:00
|
|
|
{{ $isTelLink := strings.HasPrefix .Destination "tel:" }}
|
|
|
|
{{ $isMailtoLink := strings.HasPrefix .Destination "mailto:" }}
|
|
|
|
{{ $hasSlash := in .Destination "/" }}
|
2021-01-19 23:53:27 +01:00
|
|
|
{{- if $isWebLink -}}
|
2020-12-03 16:58:35 +01:00
|
|
|
{{ $link := cond (and $isWebLink (and (not $hasSlash) (not $isExternalLink))) (path.Join "/" .Page.Dir .Destination) .Destination }}
|
|
|
|
<a href="{{ $link | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if $isExternalLink }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
|
2021-01-19 23:53:27 +01:00
|
|
|
{{- else -}}
|
2020-11-26 15:09:55 +01:00
|
|
|
{{- $separators := cond $isMailtoLink ":@." ":" -}}
|
|
|
|
{{- $regex := cond $isMailtoLink "[a-z]*:(.*)" "[a-z]*:([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})"}}
|
|
|
|
{{- $replace := cond $isMailtoLink "$1" "$1 $2 $3 $4 $5" -}}
|
2020-12-03 16:58:35 +01:00
|
|
|
{{- $string := .Destination -}}
|
2020-11-26 15:09:55 +01:00
|
|
|
{{- $params := slice -}}
|
|
|
|
|
|
|
|
{{- range split $separators "" }}
|
|
|
|
{{ $parts := split $string . }}
|
|
|
|
{{ $params = $params | append (index $parts 0) }}
|
|
|
|
{{ $string = index $parts 1 }}
|
|
|
|
{{ end }}
|
|
|
|
{{- $params = $params | append (string $string) -}}
|
|
|
|
<span
|
|
|
|
class="obfuscate{{ if $isMailtoLink }} at{{ end }}"
|
|
|
|
data-separators="{{ $separators }}"
|
|
|
|
{{ range $param_index, $param_value := $params }}
|
|
|
|
data-param{{add $param_index 1}}="{{ range $index := seq (sub (len $param_value) 1) 0}}{{ substr $param_value $index 1}}{{ end }}"
|
|
|
|
{{ end }}
|
|
|
|
data-regex="{{ $regex }}"
|
|
|
|
data-replace="{{ $replace }}"
|
|
|
|
>
|
|
|
|
</span>
|
2021-01-19 23:53:27 +01:00
|
|
|
{{- end -}}
|