This Hugo theme component provides a shortcode and a partial.
Shortcode cloakemail cloakes e-mail or other messaging (xmpp, tg, etc.) or phone (sip, tel, etc.) addresses from spamming bots. It can also be used as a partial with equivalent functionality.
Address to cloak, e.g.
{{< cloakemail "[email protected]" >}}or via named address paramater:
{{< cloakemail address="[email protected]" >}}Don't indicate other URI parameters, for instance to indicate an e-mail subject. For such feature, use instead optional query parameter (see below).
- Use
protocolto specify the protocol:{{< cloakemail address="[email protected]" protocol="xmpp" >}}or{{< cloakemail address="+1 212 664-7665" protocol="tel" >}} - Use
displayto display any text on the page instead of the address:{{< cloakemail address="[email protected]" display="Send us a mail!" >}} - Use
classto indicate CSS classes to use:{{< cloakemail address="[email protected]" class="vip company-a" >}} - Use
queryto specify a e-mail subject or other URI parameters (URI query):{{< cloakemail address="[email protected]" query="subject=Message from contact form" >}}. The query is never printed on the web page.
All parameters can be combined.
In some cases, you have to embed e-mail addresses directly in your theme code, e.g. with partials. This component can also be used as a partial, with the same functionality.
Examples:
{{ partial "cloakemail" (dict "address" "[email protected]") }}{{ partial "cloakemail" (dict "address" "[email protected]" "protocol" "xmpp") }}
Given address [email protected], the shortcode
- Writes
<span class="cloaked-e-mail" data-user="eod.enaj" data-domain="moc.elpmaxe"></span>in the web page. - A CSS rule reverses the strings back to their original values and concatenates them with
@in-between. No link is available yet. - A Javascript builds then the link by creating a
<a href=...>element.
- Add the
hugo-cloak-emailas a submodule to be able to get upstream changes latergit submodule add https://github.com/martignoni/hugo-cloak-email.git themes/hugo-cloak-email - Add
hugo-cloak-emailas the left-most element of thethemelist variable in your site's or theme's configuration fileconfig.yamlorconfig.toml. Example, withconfig.yaml:or, withtheme: ["hugo-cloak-email", "my-theme"]
config.toml,theme = ["hugo-cloak-email", "my-theme"]
- In your site, use the shortcode, this way:
or
{{< cloakemail "[email protected]" >}}{{< cloakemail address="[email protected]" >}} - You may specify parameters (see above)
Copyright © 2019 onwards, Nicolas Martignoni [email protected].
Thanks to @mxmehl for ideas and explanations about other protocols and script fingerprinting and for implementing the use of this component as a partial.
This theme component was possible because of the work done by @danieka in this pull request.