feat: Simplify management of emails and phone number
This commit is contained in:
parent
8ca72479d4
commit
1221094d75
|
@ -5,31 +5,12 @@
|
||||||
{{ $isWebLink := or $isExternalLink (eq 0 (.Destination | strings.Count ":")) }}
|
{{ $isWebLink := or $isExternalLink (eq 0 (.Destination | strings.Count ":")) }}
|
||||||
{{ $isTelLink := strings.HasPrefix .Destination "tel:" }}
|
{{ $isTelLink := strings.HasPrefix .Destination "tel:" }}
|
||||||
{{ $isMailtoLink := strings.HasPrefix .Destination "mailto:" }}
|
{{ $isMailtoLink := strings.HasPrefix .Destination "mailto:" }}
|
||||||
{{ $hasSlash := in .Destination "/" }}
|
|
||||||
{{- if $isWebLink -}}
|
{{- if $isWebLink -}}
|
||||||
|
{{ $hasSlash := in .Destination "/" }}
|
||||||
{{ $link := cond (and $isWebLink (and (not $hasSlash) (not $isExternalLink))) (path.Join "/" .Page.File.Dir .Destination) .Destination }}
|
{{ $link := cond (and $isWebLink (and (not $hasSlash) (not $isExternalLink))) (path.Join "/" .Page.File.Dir .Destination) .Destination }}
|
||||||
<a href="{{ $link | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if $isExternalLink }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
|
<a href="{{ $link | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if $isExternalLink }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
|
||||||
{{- else -}}
|
{{- else if $isMailtoLink -}}
|
||||||
{{- $separators := cond $isMailtoLink ":@." ":" -}}
|
{{ partial "contact/mail" .Destination }}
|
||||||
{{- $regex := cond $isMailtoLink "[a-z]*:(.*)" "[a-z]*:([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})"}}
|
{{- else if $isTelLink -}}
|
||||||
{{- $replace := cond $isMailtoLink "$1" "$1 $2 $3 $4 $5" -}}
|
{{ partial "contact/telephone" .Destination }}
|
||||||
{{- $string := .Destination -}}
|
|
||||||
{{- $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>
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
{{- with .Site.Data.contact.mail -}}
|
|
||||||
{{- $protocol := "mailto" -}}
|
{{- $protocol := "mailto" -}}
|
||||||
{{- $mail := . -}}
|
{{- $mail := . -}}
|
||||||
{{- $mailWithProtocol := print $protocol ":" . -}}
|
{{- $mailWithProtocol := $mail -}}
|
||||||
|
{{- if strings.HasPrefix $mail $protocol -}}
|
||||||
|
{{- $mail = substr $mail 7 -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- $mailWithProtocol = print $protocol ":" $mail -}}
|
||||||
|
{{- end -}}
|
||||||
<a
|
<a
|
||||||
class="mail obfuscate"
|
class="mail obfuscate"
|
||||||
data-link="{{ range $index := seq (sub (len $mailWithProtocol) 1) 0}}{{ substr $mailWithProtocol $index 1}}{{ end }}"
|
data-link="{{ range $index := seq (sub (len $mailWithProtocol) 1) 0}}{{ substr $mailWithProtocol $index 1}}{{ end }}"
|
||||||
>{{ range $index := seq (sub (len $mail) 1) 0}}{{ substr $mail $index 1}}{{ end }}</a>
|
>{{ range $index := seq (sub (len $mail) 1) 0}}{{ substr $mail $index 1}}{{ end }}</a>
|
||||||
{{- end -}}
|
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
{{- with .Site.Data.contact.telephone -}}
|
|
||||||
{{- $protocol := "tel" -}}
|
{{- $protocol := "tel" -}}
|
||||||
{{- $tel := . -}}
|
{{- $tel := . -}}
|
||||||
{{- $telWithProtocol := print $protocol ":" (replace $tel " " "") -}}
|
{{- $telWithProtocol := $tel -}}
|
||||||
|
{{- if strings.HasPrefix $tel $protocol -}}
|
||||||
|
{{- $tel = substr $tel 4 -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- $telWithProtocol := print $protocol ":" (replace $tel " " "") -}}
|
||||||
|
{{- end -}}
|
||||||
<a
|
<a
|
||||||
class="tel obfuscate"
|
class="tel obfuscate"
|
||||||
data-link="{{ range $index := seq (sub (len $telWithProtocol) 1) 0}}{{ substr $telWithProtocol $index 1}}{{ end }}"
|
data-link="{{ range $index := seq (sub (len $telWithProtocol) 1) 0}}{{ substr $telWithProtocol $index 1}}{{ end }}"
|
||||||
>{{ range $index := seq (sub (len $tel) 1) 0}}{{ substr $tel $index 1}}{{ end }}</a>
|
>{{ range $index := seq (sub (len $tel) 1) 0}}{{ substr $tel $index 1}}{{ end }}</a>
|
||||||
{{- end -}}
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{{- partial "contact/mail" . -}}
|
{{- partial "contact/mail" .Site.Data.contact.mail -}}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{{- partial "contact/telephone" . -}}
|
{{- partial "contact/telephone" .Site.Data.contact.telephone -}}
|
||||||
|
|
Loading…
Reference in New Issue