How to add a free, GitHub's issues-based commenting system to a Gatsby static site

February 02, 20224 min read#gatsby, #react, #github

The motivation

I want to write more in 2022. The main motivation is to share my knowledges that I learn continuously with the community.

But instead of just throwing my blogs in the sea of contents in the internet, I really want to have some interactions with the people reading my articles.

One of the way to do that is to have a comment section for every blog post, so that people can ask me more questions, or to give me feedback, so that I can improve my writings.

Since my blog is a static website hosted on GitHub Pages, I need an appropriate solution to integrate such commenting systems into my blog

The solution

There are quite many ways to integrate dynamic commenting system into a static website. I found this blog post listing “Various ways to include comments on your static site”.

For my blog, I am considering two options giscus and They work pretty much the same way. The comments are hosted on GitHub. But giscus uses GitHub’s Discussion feature and uses GitHub’s Issues feature to manage the comments.

How does it works?

giscus and uses some meta infos to identity a blog post, and map it to a GitHub’s discussion or a GitHub’s issue using GitHub’s Search API.

We will need to install an app on our repository on GitHub, and embed a javascript snippet into our website for showing comments and the form to submit comments.

Users will have to login using their GitHub’s accounts to post comments.

After some considerations, I have decided to use to integrate with GitHub’s issues for comment storage.


An example of a successful integration is here,

You should be able to see some thing like the following screenshot when opening the page:


The comments are stored in GitHub in this issue,

How to integrate?

Step 1

  • Create a repository to manage the comments as Github’s issues. You can also reuse any existing repository for this purpose.
  • Install utterances bot on the choosen repository.

Step 2

  • Create a Comment component to transform the javascript snippet into a React component. You can see customisation options on This implementation is based on this one
import React, {Component} from "react";

export default class Comments extends Component {
    this.commentBox = React.createRef(); 
  componentDidMount () {
      let scriptEl = document.createElement("script");
      scriptEl.setAttribute("src", "");
      scriptEl.setAttribute("async", true);
      scriptEl.setAttribute("repo", "antranapp/blog");
      scriptEl.setAttribute("issue-term", "title");
      scriptEl.setAttribute( "theme", "github-light");

  render() {
    return (
          <div ref={this.commentBox} className="comment-box"/>
          {/* Above element is where the comments are injected */}

Step 3

Add the Comment component into the blog post template in your Gatsby setup.

This is the simplified version of my blog post template

const BlogPost = ({ data, pageContext, location }) => {
  return (
    <Layout location={location} title={siteTitle}>
          dangerouslySetInnerHTML={{ __html: post.html }}
        <hr />
        <hr />
        <Comments/> {/* <-- The comment box is embeded at the bottom of the blog post page */}
      <nav className="blog-post-nav">

If everything work fine, you should see the comment box rendered at the bottom of the page like mine here.


A commenting system is a great way to interact with the blog’s audiences. There are many options to integrate a pre-built commenting system.

In this article, I have shown you how I integrated into my Gatsby static site to manage comments via GitHub’s Issues.

My current Gatsby setup stays completely free and everything is hosted on GitHub, from the source code, to the deployment and now also all blog posts’ comments.

Let me know what you think about this integration in the commenting section below.

Profile picture

Personal blog by An Tran. I'm focusing on creating useful mobile apps.
#Swift #Kotlin #Mobile #MachineLearning #Minimalist

© An Tran - 2023