Adding "Reply via email" to a hugo site

6th May 2023 from jc's blog

We’re not all running our blogs on ActivityPub yet, so how do we allow people to comment on our posts? The most straightforward way for me was to simply add a link to email me about a post to the posts, with an automatically populated Subject: header based on the title of the post.

The below snippet can be used on your blog post layout to have Hugo add a link that will open a mail client with your e-mail and the Re: Your blog post title already filled out:

<a href="mailto:{{ $ }}?subject={{ replace (printf "Re: %s" .Page.Title) "\"" "'" }}">reply via email</a>

Double quotes in the blog title are replaced with single quotes to not mess up the HTML.

The $ value comes from your Hugo configuration file - in my case, config.toml. That section like this:

name = "John Doe"
email = ""

You can also simply hardcode your mail address into your template, if you don’t wanna specify it globally.

reply via email