Starting an R-related blog has been on my personal to-do list for quite some time1. This month I decided that I had procrastinated enough, so I went ahead and created this site using blogdown, Hugo and the hugo-xmin theme. In the process, I learned a couple of things that may be worth sharing:
- How to enable comments and disable them on selected pages.
- How to set up multilingual mode.
Since this is quite a bit of information, I will split it into two different posts. My advice is biased towards the hugo-xmin theme, which is a “boilerplate” theme for those wanting to learn more about customising hugo websites2. If you want to read more about the theme, I recommend the templates chapter of the blogdown book or the demo website at https://xmin.yihui.org/.
Making changes to the theme
Adding basic features to the hugo-xmin is relatively straight-forward given the fantastic set of demos available as pull requests in the theme’s Github repo. When implementing these changes to your own website, the recommended workflow is to make the changes in the layouts/
directory under the root directory of your website instead of layouts/
directory under themes/hugo-xmin/
. This makes it easier for you to keep track of the changes that you have made that stray from original theme.
your-website/
├── config.toml
├── ...
├── themes/
│ └── hugo-xmin/
│ ├── ...
│ └── layouts/
│ ├── ...
│ └── partials
│ ├── foot_custom.html
│ ├── footer.html
│ ├── head_custom.html
│ └── header.html
└── layouts
└── partials
├── foot_custom.html └── head_custom.html
Enabling Disqus comments
Adding basic features to the hugo-xmin is relatively straight-forward given the fantastic set of demos available as pull requests in the theme’s Github repo. Pull request #4, for example, explains how to enable Disqus comments in your site.
This example calls on one of Hugo’s internal templates, _internal/disqus.html
. If you want to further customise the behaviour of Disqus comments, then it may be worthwhile to explore the source code the template.
Selectively disabling Disqus comments
The above example will enable Disqus comments on all pages, including those where comments may not really be that useful, like in the Categories, Tags or About pages. For example, below is a screenshot of the Tags page of the hugo-xmin Disqus demo.
Thankfully, one of Yihui’s comments on the PRs discussion also explained how to selectively disable Disqus comments on given pages via the YAML metadata.
In the above example, the if condition ensures that Disqus comments won’t be rendered if the disable_comments
parameter is set to true
in a given page.
Hussain Alsalman recently proposed an alternative approach that enables Disqus comments only for pages under the content/post/
directory. Unlike the previous examples, this approach would require creating a new single.html
template under layouts/post/
. You may prefer this implementation if you are creating a website with many types of content directories (e.g. content/software/
, content/workshops/
, etc.) and you would rather not have to change the YAML metadata of every file that you create under these directories.
Extending to utterances 🔮
I went down the Disqus rabbit-hole before I learned about utterances, which is a lightweight, open-source, and ad-free alternative to Disqus comments. Luckily, extending the above steps to utterances was a breeze.
If you want to learn more about migrating from Disqus to utterances, I highly recommend Maëlle’s blog post on the subject. In her post, she explains what motivated her move, how she exported her old comments, and how she added utterances to her theme.
One thing to keep in mind before choosing utterances is that you will be restricting comments to people who either have or are willing to open a Github account. This may therefore not be the best option for blogs intended for a general audience.
Conclusion
In this post, I went into a lot of detail over a very narrow subject: comments. My intention was to summarise what I learned so that I can refer back to it later, and to hopefully help others who are getting started with Hugo themes. Please let me know if this helped or if anything was unclear!
In the next post, I will explain how to enable multilingual mode in hugo-xmin.