Last active
May 9, 2017 03:40
-
-
Save renatocarvalho/afda8238f57f57b94ae5 to your computer and use it in GitHub Desktop.
Middleman email obfuscate helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ==================================== | |
# Obfuscate email | |
# Adapted from: | |
# http://stackoverflow.com/questions/483212/effective-method-to-hide-email-from-spam-bots2 | |
# Usage: | |
# = mailto('[email protected]', 'Get in touch', 'btn btn--nav') | |
# ==================================== | |
MAIL_TO = 'mailto:' | |
AT = '@' | |
DOT = '.' | |
def mailto email="[email protected]", string="contact me", classes | |
comp = email.split("@") | |
# process string, if it is an email address | |
if string.include?("@") then | |
string.gsub!("@", AT + "‌").gsub!(".", DOT) | |
end | |
return "<a class=\"#{classes}\" href='javascript:void(0)' rel='nofollow' onclick='str1=\"#{comp[0]}\";str2=\"#{comp[1]}\";this.href=\"#{MAIL_TO}\" + str1 + \"@\" + str2'>#{string}</a>" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems legit, but https://github.com/amsardesai/middleman-protect-emails worked for me (for future generations who come here looking for this functionality).