HowTo — Thinking 🤔 2022.12.25 2022.12.29

Mastodon Redirect From Your Domain Using Hugo

A how-to guide to making people able to search for me with @me@tormodh.net on Mastodon

I have my own domain, and I have a mastodon account. When I read Scott Hanselman’s blogpost Use your own user @ domain for Mastodon discoverability with the WebFinger Protocol without hosting a server, I didn’t wait long before… adding that as a todo to my list.

Upon reading it, I found that it explained the concept of Webfinger quite well. Still, it was Maarten Balliauw whose comment drew my attention to his post on how to do this for a static website, notably Jekyll.

I wanted to do the same, and with Hugo already set up I startet the journey:

First, find the info about your mastodon profile

In a browser, or using curl, open:

https://mastodon.server/.well-known/webfinger?resource=acct:accountname@mastodon.server

This gives you a JSON text bit of all you need to do the redirect.

Second, in your site’s static folder (outside of content)

Create a folder named .well-known. Inside this folder create a file named webfinger (like that, no file extension)

Inside this file, paste all the json from the first part. Thats that,

Thirdly, just to be sure

Run Hugo with hugo server and open localhost:1313/.well-known/webfinger?resource=acct:desiredname@your.domain

Now it is just to generate and publish your site, and it should be working. Test it out by searching for you@yourdomain.site in Mastodon.

Note: there are no logic involved

Any username and your domain will return the same Mastodon redirect. If it should do any redirect, that will be another bit of work — and possibly not in Hugo?