feat: Add obfuscates partials

This commit is contained in:
Simon 2021-07-03 16:03:24 +02:00
parent 84539d10ae
commit b8ae0a19ca
7 changed files with 31 additions and 22 deletions

View File

@ -15,6 +15,10 @@ cd themes
git submodule add https://git.weko.io/kosssi/hugo-theme-lowtech.git git submodule add https://git.weko.io/kosssi/hugo-theme-lowtech.git
``` ```
## Contact
Pour la gestion de contact il est possible d'utiliser des shortcodes spécifiques `{{< mail >}}` ou `{{< tel >}}`
## Inspirations ## Inspirations
- https://github.com/yuin/goldmark/issues/59 - https://github.com/yuin/goldmark/issues/59

View File

@ -1,19 +0,0 @@
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();

9
assets/js/obfuscates.js Normal file
View File

@ -0,0 +1,9 @@
export default function abfuscates() {
const obfuscates = document.getElementsByClassName("obfuscate");
while (obfuscates.length > 0) {
const element = obfuscates[0]
element.href = element.dataset.link.split("").reverse().join("");
element.innerText = element.innerText.split("").reverse().join("");
element.classList.remove('obfuscate');
}
}

View File

@ -0,0 +1,3 @@
.obfuscate
unicode-bidi: bidi-override
direction: rtl

View File

@ -1,3 +1,9 @@
{{- with .Site.Data.contact.mail -}} {{- with .Site.Data.contact.mail -}}
<a class="mail" href="mailto:{{ .}}">{{ . }}</a> {{- $protocol := "mailto" -}}
{{- $mail := . -}}
{{- $mailWithProtocol := print $protocol ":" . -}}
<a
class="mail obfuscate"
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>
{{- end -}} {{- end -}}

View File

@ -1,3 +1,9 @@
{{- with .Site.Data.contact.telephone -}} {{- with .Site.Data.contact.telephone -}}
<a class="tel" href="tel:{{ . }}">{{ . }}</a> {{- $protocol := "tel" -}}
{{- $tel := . -}}
{{- $telWithProtocol := print $protocol ":" (replace $tel " " "") -}}
<a
class="tel obfuscate"
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>
{{- end -}} {{- end -}}

View File

@ -1,5 +1,5 @@
{{ $js := resources.Get "js/main.js" }} {{ $js := resources.Get "js/main.js" }}
{{ with $js }} {{ with $js }}
{{ $secureJS := . | resources.Minify | resources.Fingerprint }} {{ $secureJS := . | js.Build | resources.Minify | resources.Fingerprint }}
<script src="{{ $secureJS.Permalink }}" integrity="{{ $secureJS.Data.Integrity }}"></script> <script src="{{ $secureJS.Permalink }}" integrity="{{ $secureJS.Data.Integrity }}"></script>
{{ end }} {{ end }}