Using GitHub as Commenting Platform
Integrate Utterances' GitHub Issue Commenting to Hexo
If you run a blog, it is always advisable to integrate a commenting system, in order to get feedback on your posts from your readers.
So did I, when I start this blog and I decided to use the Disqus platform, as it was very easy to integrate … but I always had a bad feeling about a third-party platform collecting data from my readers. Disqus is probably not without reason under criticism by many people in the community.
As I host this blog at GitHub (see A New Blog (Part One): VS Code, Hexo and GitHub Pages) I was looking for a solution to host the comments also on my prefered platform. There were some solutions, which uses GitHub Issues for this and wanted to implement something like that someday.
As I read a post from on Thomas Lavesques’ blog, to solve another problem, his commenting section came to my attention: utteranc.es … exactly the solution I needed! Thanx guys…
On their website is a small configurator for a script to implement in each post, which needs only few information:
- Name of the Repo
- How the mapping of the post to the Issues should work
- Name of the Theme, in order to fit to the colors of the blog
The script had to be included to my Hexo article.js
:
1 | <% if (!index && post.comments){ %> |
That’s pretty much it. On entering the first comment, Utterances told me to install the needed GitHub App to my repo, in order to make it work … and done.
The result you see below …
UPDATE…
The utterances script tag has the attribute theme
, to tell utterances which style should be delivered. There are several themes available, but if users are able to switch between light or dark mode on the page (see Hexo and the Dark Mode), the comment block should change to an suitable theme also.
On order to respond on a mode change, it is necessary to write a more dynamic script loading.
First we define a function in a global script file to load the utterances script via JS:
1 | function insertUtterancesCommentBlock() { |
Then we change the placement in the EJS file, by defining a placeholder and ensuring that the script above is loaded, before we call it:
1 | <div id="comment-placeholder"></div> |
On my blog, everytime the user switches between light/dark mode the body
tag will be decorated with the data tag data-theme
and the value of the mode. To keep the loading of the utterances script independent from this functionality, we just have to listen to this change via MutationObserver
:
1 | //observe theme change, to adjust comment block theme |
You can interact with this article (applause, criticism, whatever) by mention it in one of your posts, which will also be shown here as a Webmention ... or you leave a good old comment with your GitHub account.
Webmentions
No Webmentions yet...
In case your blog software can't send Webmentions, you can use this form to submit me a mention of this article...
Comments