Add files to repository

This commit is contained in:
Nicolas Martignoni 2019-02-05 21:36:47 +01:00 committed by GitHub
parent baa75498aa
commit 27c95eedd6
3 changed files with 64 additions and 0 deletions

26
README.md Normal file
View File

@ -0,0 +1,26 @@
# hugo-cloak-email
## About
This is not a standalone theme. It is a [Hugo](https://gohugo.io) theme component providing a shortcode: `cloakemail` to cloak any e-mail address from spamming bots.
## Usage
1. Add the `hugo-cloak-email` as a submodule to be able to get upstream changes later `git submodule add https://github.com/martignoni/hugo-cloak-email.git themes/hugo-cloak-email`
2. Add `hugo-cloak-email` as the left-most element of the `theme` list variable in your site's or theme's configuration file `config.yaml` or `config.toml`. Example, with `config.yaml`:
```yaml
theme: ["hugo-cloak-email", "my-theme"]
```
or, with `config.toml`,
```toml
theme = ["hugo-cloak-email", "my-theme"]
```
3. In your site, use the shortcode, this way:
```go
{{< cloakemail "john.doe@example.com" >}}
```
### Credits
This theme component was possible because of the work done by
[@danieka](https://github.com/danieka) in [this pull request](https://github.com/gohugoio/hugo/pull/3935).

View File

@ -0,0 +1,20 @@
{{- $parts := split (index .Params 0) "@" -}}
{{- $user := (index $parts 0) -}}
{{- $domain := (index $parts 1) -}}
<style type="text/css">
.cloaked-e-mail:before {
content:attr(data-domain) "\0040" attr(data-user);
unicode-bidi:bidi-override;
direction:rtl;
}
</style>
<span class="cloaked-e-mail" data-user="{{ range $index := seq (sub (len $user) 1) 0}}{{ substr $user $index 1}}{{ end }}" data-domain="{{ range $index := seq (sub (len $domain) 1) 0}}{{ substr $domain $index 1}}{{ end }}"></span>
<script id="id">
var scriptTag = document.getElementById("id");
var link = document.createElement("a");
var mail = "{{ range $index := seq (sub (len $user) 1) 0}}{{ substr $user $index 1}}{{ end }}".split('').reverse().join('') + "@" + "{{ range $index := seq (sub (len $domain) 1) 0}}{{ substr $domain $index 1}}{{ end }}".split('').reverse().join('');
link.href = "mailto:" + mail;
link.innerText = mail;
scriptTag.parentElement.insertBefore(link, scriptTag.previousElementSibling);
scriptTag.parentElement.removeChild(scriptTag.previousElementSibling)
</script>

18
theme.yaml Normal file
View File

@ -0,0 +1,18 @@
# theme.yaml configuration file
name: Cloak e-mail adresses
license: GPLv3
licenselink: https://github.com/martignoni/hugo-cloak-email/blob/master/LICENSE
description: Hugo theme component for cloaking e-mail address, preventing spam
homepage: https://github.com/martignoni/hugo-cloak-email
tags:
- component
- e-mail address
- mail address
features:
- cloak e-mail addresses
min_version: 0.40.0
author:
name: Nicolas Martignoni
homepage: https://martignoni.net