Link your Hugo website and Mastodon Account together: Make Your Blog Discoverable with Just Your Domain Name

Do you have a website or a blog built with Hugo? (of course you do!)
Do you also have a Mastodon account?

Would you like people to be able to find you on Mastodon even using just the domain name of your blog?

For example, if your name is John Doe and your blog is hosted on https://www.doe.com wouldn’t it be nice if people could find you by searching for you on Mastodon as

@john@doe.com

instead of having to remember your looong mastodon account name

@johndoe43210@mastodon.social

And what if I tell you that you don’t need to install and set-up a Mastodon server to obtain this?

All you really need is just to add a single file to your existing website.

I’ve created a small Python script to help you do this automatically in less than a minute

The operation is quite simple: every time someone searches for a user on Mastodon (for example: @john@doe.com), the Mastodon server tries to contact the domain (doe.com) to ask about user credentials, by accessing a page under https://doe.com/.well-known/webfinger?resource=acct:john@doe.com using a GET method.

All my script does is copy these credentials from the Mastodon server that is hosting your account, and insert them into your website or blog created with Hugo in order to mimick the same directory structure.

In order to make it work, after running my script please remember to execute Hugo to build your website again and deploy.

Credits

I couldn’t have created this script without the helpful article written by Maarten Balliauw on his personal blog, which you can find at https://blog.maartenballiauw.be/post/2022/11/05/mastodon-own-donain-without-hosting-server.html

You can download my script from this URL

You can find my script here: https://github.com/fmaida/mastodon2hugo

4 Likes