Skip to content

Commit 27b9c74

Browse files
authored
Add files to repository
1 parent 643ff54 commit 27b9c74

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# hugo-cloak-email
2+
3+
## About
4+
5+
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.
6+
7+
## Usage
8+
9+
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`
10+
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`:
11+
```yaml
12+
theme: ["hugo-cloak-email", "my-theme"]
13+
```
14+
or, with `config.toml`,
15+
```toml
16+
theme = ["hugo-cloak-email", "my-theme"]
17+
```
18+
3. In your site, use the shortcode, this way:
19+
```go
20+
{{< cloakemail "john.doe@example.com" >}}
21+
```
22+
23+
### Credits
24+
25+
This theme component was possible because of the work done by
26+
[@danieka](https://github.com/danieka) in [this pull request](https://github.com/gohugoio/hugo/pull/3935).

layouts/shortcodes/cloakemail.html

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{{- $parts := split (index .Params 0) "@" -}}
2+
{{- $user := (index $parts 0) -}}
3+
{{- $domain := (index $parts 1) -}}
4+
<style type="text/css">
5+
.cloaked-e-mail:before {
6+
content:attr(data-domain) "\0040" attr(data-user);
7+
unicode-bidi:bidi-override;
8+
direction:rtl;
9+
}
10+
</style>
11+
<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>
12+
<script id="id">
13+
var scriptTag = document.getElementById("id");
14+
var link = document.createElement("a");
15+
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('');
16+
link.href = "mailto:" + mail;
17+
link.innerText = mail;
18+
scriptTag.parentElement.insertBefore(link, scriptTag.previousElementSibling);
19+
scriptTag.parentElement.removeChild(scriptTag.previousElementSibling)
20+
</script>

theme.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# theme.yaml configuration file
2+
3+
name: Cloak e-mail adresses
4+
license: GPLv3
5+
licenselink: https://github.com/martignoni/hugo-cloak-email/blob/master/LICENSE
6+
description: Hugo theme component for cloaking e-mail address, preventing spam
7+
homepage: https://github.com/martignoni/hugo-cloak-email
8+
tags:
9+
- component
10+
- e-mail address
11+
- mail address
12+
features:
13+
- cloak e-mail addresses
14+
min_version: 0.40.0
15+
16+
author:
17+
name: Nicolas Martignoni
18+
homepage: https://martignoni.net

0 commit comments

Comments
 (0)