Hugo Giscus Module

Donate

Become a backer or sponsor to support our work.

Sponsors

This module add support for Giscus, a comments system powered by GitHub Discussions. Let visitors leave comments and reactions on your website via GitHub!

Modulegithub.com/hugomods/giscus
StatsGitHub Stars Used By Used By Used By Used By

Features

  • Flexible and Configurable.
  • JS APIs: change theme on the fly, it’s usually used in the case of color(dark/light) changed.
  • Multiple repos.

Installation

Requires extended Hugo and Go.

Import the github.com/hugomods/giscus into your site configuration.

hugo.yaml

1module:
2  imports:
3  - path: github.com/hugomods/giscus

hugo.toml

1[module]
2  [[module.imports]]
3    path = 'github.com/hugomods/giscus'

hugo.json

1{
2   "module": {
3      "imports": [
4         {
5            "path": "github.com/hugomods/giscus"
6         }
7      ]
8   }
9}

Site Parameters

See how to configure Gisucs.

NameTypeRequiredDefaultDescription
endpointStringYhttps://giscus.app/The client script endpoint.
repoStringY-The GitHub repository, user/repo.
repo_idStringN-The GitHub repository ID.
categoryStringYGeneralDiscussion category.
category_idStringY-Discussion category ID.
mappingStringNpathnameThe mapping between the embedding page and the embedded discussion.
strict_matchingStringNtrueUse strict title matching.
themeStringNpreferred_color_scheme
input_positionStringNtopThe input position. Available options: top or bottom.
reactionsStringNtrueEnable reactions for the main post.
lazy_loadingStringNtrueLoad the comments lazily.
languages_mappingObjectN-The languages mapping from site language to Giscus language.

See the configuration for details.

Usage

See the example site and it’s source code.

Configuration

Firstly, we’ll need to tweak the site parameters listed above.

Import Script

1{{ partial "giscus/script" . }}

Or with custom options.

1{{ partial "giscus/script-with-options" .Site.Params.blog.giscus }}

By default, the Giscus client will look up the placeholder element that with the giscus class, such as,

1<div class="giscus">YOUR COMMENTS WILL BE PLACED INSIDE</div>

Otherwise, the comments will be rendered where the script placed.

JS APIs

You may want to change the Giscus theme on the fly, a common example is changing the Giscus to the corresponding theme when the user switches colors(dark/light).

1import Giscus from 'mods/giscus/js';
2
3const giscus = new Giscus();
4giscus.setTheme('dark');

You can find the real example on the example site.