feat: Eviter les spams sur mail et téléphone

fixes: #1
This commit is contained in:
Simon 2020-11-26 15:09:55 +01:00
parent 7b2aa4c8e3
commit bb37eeba3b
4 changed files with 57 additions and 5 deletions

19
assets/js/main.js Normal file
View File

@ -0,0 +1,19 @@
const obfuscates = document.getElementsByClassName("obfuscate")
for (const element of obfuscates) {
const link = document.createElement("a")
const separators = element.dataset.separators
const protocol = element.dataset.param1.split("").reverse().join("")
let url = protocol
for (let i = 0; i < separators.length; i++) {
url += separators[i] + element.dataset["param" + (i+2)].split("").reverse().join("")
}
let text = element.dataset.param2.split("").reverse().join("")
for (let i = 1; i < separators.length; i++) {
text += separators[i] + element.dataset["param" + (i+2)].split("").reverse().join("")
}
link.innerText = url.replace(new RegExp(element.dataset.regex, 'i'), element.dataset.replace)
link.href = url
link.rel = "nofollow"
element.parentElement.insertBefore(link, element);
}
while (obfuscates.length > 0) obfuscates[0].remove()

View File

@ -221,8 +221,15 @@ hr
.card-body
font-size: .9rem
.md
max-width: 645px
margin-left: auto
margin-right: auto
.obfuscate:before
content: attr(data-param2)
unicode-bidi: bidi-override
direction: rtl
&.at
content: attr(data-param4) "\002E" attr(data-param3) "\0040" attr(data-param2)

View File

@ -2,8 +2,34 @@
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" }}
{{ $isNotWebLink := or (not $isExternalLink) (eq 1 (strings.Count .Destination ":")) }}
{{ $isTelLink := strings.HasPrefix .Destination "tel:" }}
{{ $isMailtoLink := strings.HasPrefix .Destination "mailto:" }}
{{ $hasSlash := in .Destination "/" }}
{{ $path := cond (or (or $isTelLink $isMailtoLink) $hasSlash) .Destination (path.Join "/" .Page.Dir .Destination) }}
<a href="{{ $path | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if $isExternalLink }} target="_blank" rel="noopener"{{ end }}{{ if $isTelLink }} rel="nofollow"{{ end }}>{{ .Text | safeHTML }}</a>
{{ $link := cond (or (or $isExternalLink $isNotWebLink) $hasSlash) .Destination (path.Join "/" .Page.Dir .Destination) }}
{{ if $isNotWebLink }}
{{- $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" -}}
{{- $string := $link -}}
{{- $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>
{{ else }}
<a href="{{ $link | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if $isExternalLink }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
{{ end }}

View File

@ -5,8 +5,8 @@
<h3>Mairie de Crémeaux</h3>
<p>Place de Pierre-Bénite</p>
<p>42260 Crémeaux</p>
<p><a href="tel:0477625067" rel="nofollow">04 77 62 50 67</a></p>
<p><a href="mailto:mairie@cremeaux.fr">mairie@cremeaux.fr</a></p>
<p>{{ .RenderString "[](tel:0477625067)" }}</p>
<p>{{ .RenderString "[](mailto:mairie@cremeaux.fr)" }}</p>
<p>
<a href="/actualites/index.xml"><img src="/icons/rss.svg" alt="Flux RSS de l'actualité à Crémeaux" title="Flux RSS de l'actualité à Crémeaux" class="icons" /></a>
<a target="_blank" rel="noopener" href="https://www.facebook.com/vivre.a.cremeaux/"><img src="/icons/facebook.svg" alt="Facebook : Vivre à Crémeaux" title="Facebook : Vivre à Crémeaux" class="icons" /></a>