From 0af8a81a73cf9136064f0f9e7c3fd69fc2217a7e Mon Sep 17 00:00:00 2001 From: Jacek Lebioda <jacek.lebioda@uni.lu> Date: Wed, 28 Aug 2019 12:22:09 +0200 Subject: [PATCH] Adding mailto: obfuscation --- Gemfile | 1 + _plugins/hook_mailto_email_protector.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 _plugins/hook_mailto_email_protector.rb diff --git a/Gemfile b/Gemfile index 7b1e783..0acaa10 100644 --- a/Gemfile +++ b/Gemfile @@ -25,6 +25,7 @@ gem 'jekyll-theme-lcsb-default', '~> 0.2.18', :git => "https://git-r3lab.uni.lu/ group :jekyll_plugins do gem "jekyll-paginate-v2", "~> 1.7" gem "jekyll-feed", "~> 0.6" + gem "jekyll-email-protect" end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem diff --git a/_plugins/hook_mailto_email_protector.rb b/_plugins/hook_mailto_email_protector.rb new file mode 100644 index 0000000..8b8af8e --- /dev/null +++ b/_plugins/hook_mailto_email_protector.rb @@ -0,0 +1,16 @@ +Jekyll::Hooks.register([:pages, :posts, :documents], :pre_render) do |post| + # This will run every time the website is built + + # Include a plugin (needs to be in gemfile) + include Jekyll::EmailProtect::EmailProtectionFilter + + # Using a simpler version of email regexp + email_regexp = /mailto\:(?:[\'\"]*)(?:[\w+\-]\.?)+@[a-z\d\-]+(?:\.[a-z]+)*\.[a-z]+(?:[\'\"]*)/i + + # Take post's content, and transform every occurence of the following regexp (an email) + post.content = post.content.gsub(email_regexp) { + # For every occurence, apply protection function: + |param| "mailto:" + Jekyll::EmailProtect::EmailProtectionFilter::encode_email(param[7..-1].delete("'").delete('"')) + } +end + -- GitLab