Skip to content

Commit

Permalink
feat: add email-protect shortcode with configurable email and link text
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Oct 30, 2024
1 parent 1b8c7bb commit d316456
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion hugo-site/content/faq/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,4 @@ special interests.
You can [donate via credit card or cryptocurrency](/donate), or donate through our [Ghost Key](/ghostkey/)
mechanism to establish a verifiable cryptographic identity.

If you are in a position to make a larger contribution or grant please email Ian at {{< email-protect >}}.
If you are in a position to make a larger contribution or grant please email Ian at {{< email-protect "[email protected]" "Ian Clarke" >}}.
10 changes: 6 additions & 4 deletions hugo-site/layouts/shortcodes/email-protect.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{{ $id := now.UnixNano }}<script>(function(){
const encoded = "[email protected]";
{{ $email := .Get 0 }}
{{ $text := .Get 1 | default $email }}
{{ $encoded := $email | strings.ToLower | strings.Rot13 }}
<script>(function(){
const decode = str => str.replace(/[a-zA-Z]/g, c =>
String.fromCharCode((c <= 'Z' ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26)
);
const email = decode(encoded);
document.write(`<a href="mailto:${email}">${email}</a>`);
const email = decode("{{ $encoded }}");
document.write(`<a href="mailto:${email}">${decode("{{ $text | strings.Rot13 }}")}</a>`);
})();</script>

0 comments on commit d316456

Please sign in to comment.