Skip to content

Commit

Permalink
fix: Improve ROT13 encoding in email-protect shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Oct 30, 2024
1 parent d39e07e commit fe7b47d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions hugo-site/layouts/shortcodes/email-protect.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{{ $email := .Get 0 }}
{{ $text := .Get 1 | default $email }}
<script>(function(){
const rot13 = str => str.replace(/[a-zA-Z]/g, c =>
String.fromCharCode((c <= 'Z' ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26)
);
const email = rot13("{{ $email | lower }}");
const text = rot13("{{ $text | lower }}");
const rot13 = str => str.replace(/[a-zA-Z]/g, c => {
const charCode = c.charCodeAt(0);
const isUpperCase = c <= 'Z';
const base = isUpperCase ? 65 : 97;
return String.fromCharCode(base + (charCode - base + 13) % 26);
});
const email = rot13("{{ $email }}");
const text = rot13("{{ $text }}");
document.write(`<a href="mailto:${email}">${text}</a>`);
})();</script>

0 comments on commit fe7b47d

Please sign in to comment.