diff --git a/assets/js/email.js b/assets/js/email.js new file mode 100644 index 00000000..4d45f4cf --- /dev/null +++ b/assets/js/email.js @@ -0,0 +1,13 @@ +(function () { + const links = document.querySelectorAll(".email-link"); + links.forEach((link) => { + let email = atob(link.getAttribute("data-email")); + const subject = link.getAttribute("data-subject"); + let mailto = email.startsWith("mailto:") ? email : "mailto:" + email; + + if (subject) { + mailto += (mailto.includes("?") ? "&" : "?") + "subject=" + encodeURIComponent(subject); + } + link.href = mailto; + }); +})(); diff --git a/layouts/_default/single.html b/layouts/_default/single.html index a6c78f9f..d1c2719d 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -53,11 +53,18 @@ {{ if $replyByEmail }} + class="email-link m-1 rounded bg-neutral-300 p-1.5 text-neutral-700 hover:bg-primary-500 hover:text-neutral dark:bg-neutral-700 dark:text-neutral-300 dark:hover:bg-primary-400 dark:hover:text-neutral-800" + href="#" + data-email="{{ site.Params.Author.email | base64Encode }}" + data-subject="{{ replace (printf "Reply to %s" .Title) "\"" "'" }}"> {{ i18n "article.reply_by_email" | default "Reply by Email" }} + {{ end }} @@ -76,7 +83,7 @@ {{ if .Params.showComments | default (site.Params.article.showComments | default false) }} {{ if templates.Exists "partials/comments.html" }}