Setting up Github comments on your blog with Giscus
Posted on September 3, 2022 • 4 minutes • 765 words
Table of contents
Wait, what happened to Utterances?
In my previous post, I described how to add a GitHub-based comments system to your blog using Utterances. In all the excitement of a free and open source comments platform for my blog, I forgot to check to see if it was still maintained, and it appears to have recently been mothballed. Utterances still works fine - for now, but it’s best practice to implement maintained dependencies.
The folk at Giscus have taken the idea of Utteraces, expanded upon it and made it even better. Like Utterances, Giscus is written in typescript, uses the GitHub API, is free and open source and relies on an app to perform the writes to a public repo which you own; however there are some key differences. With Giscus, they use Discussions instead of issues. It’s more expandable and configurable and has some powerful new features, like lazy loading comments and the ability to place the input box at the top of the comments. It’s also slightly simpler to install, with relaxed repository requirements.
Giscus uses the discussions API by GitHub in order to facilitate the comments window which you can subsequently supply in your blog’s code. Like Utterances, this means no adverts, no tracking and no irritating 3rd party to deal with. You can provide a comments box to each page you wish. Simply find a suitable place in your blogs’ code and bob’s your uncle. Lets take a look at getting set up.
It’s worth knowing that commenters will need a GitHub account to make a comment or react with an emoji.
Getting set up
First of all create yourself a new GitHub repository and set it to public. It needs to be public because that’s how your commenters will be able to comment. Unlike Utternaces, you don’t need to create your repository under the
github.iodomain. Giscus works with the standard
Install the Giscus app to your new public GitHub repository.
Generate your Giscus code. You can generate your own code and customisations here: https://giscus.app
…or you can use the below template edit to taste.
Remember to enter the name of your new public repo with the Giscus app enabled on line 3:
There’s a bunch of colour themes you can use for your new comments box, but if you’d rather not bother and just assume the colour of the existing CSS, use the transparent themes such as
transparent_dark (seen in the comments section below). Check out https://giscus.app/
for all of the possible customisations.
- Now you have your code, you can now cut and paste it into your site where you want the comments to appear. This blog is currently using Hugo, and the theme I’m running contains a partial for blog pages. For me, this was the perfect place for blog article comments and it was on the following path:
You can see on this article where this ends up being when the site renders at the footer of the page. Here’s the file with some extra context:
This shows that the comments will appear as part of each blog post article, and before the “socials” which is what delivers the Twitter, LinkedIn and Stack Overflow etc links at the footer of the page.
Occasionally you’ll want to delete comments, such as when someone posts something which violates your policies, or to tidy up tests etc. Fortunately you can manage comments in the exact same way as your GitHub comments on discussions. Simply delete the comment in the relevant discussion in your GitHub repository. This works for users too (as long as they made the comments in the first place).
Whichever you decide to use, Utterances or Giscus, they’re both a nice and elegant way of providing an interaction interface with your readers, and well worth a look.