In Jekyll set a variable for the mail, e.g. in the _config.yml
email: [email protected]
then use it in your page
Reach me under: {{ site.email | mailObfuscate }}
which will generate the following HTML
<a href="#" data-contact="bmFtZUBtYWlsLmNvbQ== " target="_blank" onfocus="this.href = 'mailto:' + atob(this.dataset.contact)">
<script type="text/javascript">document.write(atob("bmFtZUBtYWlsLmNvbQ== "));</script>
</a>
This uses some simple obfuscation techniques of url encode and base64 encode the mail and use JS to support the link and write it to HTML programmatically. This is certainly not bulletproof, but a good shield and in combination with a good spam filter this will fix your problem with mail crawlers.
These techniques are partly from http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/
Thanks for this nice simple approach, which works nicely in my Jekyll project. However, the use of URI::encode is now deprecated, and generates a warning
mail_obfuscate.rb:6: warning: URI.escape is obsolete
. I'm not a Ruby programmer - I tried usingURI.encode_www_form_component()
as suggested on some other sites, but this resulted in the "@" of the email address appearing on the page as "%20". Is there a simple way to fix this so that it runs without warnings?