Skip to content

Commit

Permalink
docs: add giscus comments system (#96)
Browse files Browse the repository at this point in the history
* chore: rename comment to comments

* docs: add giscus comments

* docs: update
  • Loading branch information
imfing authored Sep 26, 2023
1 parent adf5a11 commit 46dea71
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 23 deletions.
1 change: 1 addition & 0 deletions exampleSite/content/docs/advanced/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ This section covers some advanced topics of the theme.
{{< cards >}}
{{< card link="multi-language" title="Multi-language" icon="translate" >}}
{{< card link="customization" title="Customization" icon="pencil" >}}
{{< card link="comments" title="Comments System" icon="chat-alt" >}}
{{< /cards >}}
39 changes: 39 additions & 0 deletions exampleSite/content/docs/advanced/comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: Comments System
linkTitle: Comments
---

Hextra supports adding comments system to your site.
Currently [giscus](https://giscus.app/) is supported.

<!--more-->

## giscus

[giscus](https://giscus.app/) is a comments system powered by [GitHub Discussions](https://docs.github.com/en/discussions). It is free and open source.

To enable giscus, you need to add the following to the site configuration file:

```yaml {filename="hugo.yaml"}
params:
comments:
enable: false
type: giscus

giscus:
repo: <repository>
repoId: <repository ID>
category: <category>
categoryId: <category ID>
```
The giscus configurations can be constructed from the [giscus.app](https://giscus.app/) website. More details can also be found there.
Comments can be enabled or disabled for a specific page in the page front matter:
```yaml {filename="content/docs/about.md"}
---
title: About
comments: true
---
```
16 changes: 8 additions & 8 deletions exampleSite/hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,19 @@ params:
enable: true
base: "https://github.com/imfing/hextra/edit/main/exampleSite/content"

comment:
comments:
enable: false
type: giscus

# https://giscus.app/
giscus:
repo: "imfing/hextra"
repoId: "R_kgDOJ9fJag"
category: "General"
categoryId: "DIC_kwDOJ9fJas4CY7gW"
# mapping: "pathname"
repo: imfing/hextra
repoId: R_kgDOJ9fJag
category: General
categoryId: DIC_kwDOJ9fJas4CY7gW
# mapping: pathname
# strict: 0
# reactionsEnabled: 1
# emitMetadata: 0
# inputPosition: "top"
# lang: "en"
# inputPosition: top
# lang: en
2 changes: 1 addition & 1 deletion layouts/_default/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1>{{ .Title }}</h1>
</div>
<div class="mt-16"></div>
{{ partial "components/last-updated.html" . }}
{{ partial "components/comment.html" . }}
{{ partial "components/comments.html" . }}
</main>
</article>
</div>
Expand Down
3 changes: 2 additions & 1 deletion layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ <h1 class="text-center mt-2 text-4xl font-bold tracking-tight text-slate-900 dar
<div class="content">
{{ .Content }}
</div>
{{ partial "components/comment.html" . }}
<div class="mt-16"></div>
{{ partial "components/comments.html" . }}
</main>
</article>
</div>
Expand Down
2 changes: 1 addition & 1 deletion layouts/blog/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h1 class="mt-2 text-4xl font-bold tracking-tight text-slate-900 dark:text-slate
{{ partial "components/last-updated.html" . }}
{{ .Scratch.Set "reversePagination" true }}
{{ partial "components/pager.html" . }}
{{ partial "components/comment.html" . }}
{{ partial "components/comments.html" . }}
</main>
</article>
</div>
Expand Down
3 changes: 1 addition & 2 deletions layouts/docs/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
<h1>{{ .Title }}</h1>
{{ .Content }}
</div>
<div class="mt-16"></div>
{{ partial "components/last-updated.html" . }}
{{ partial "components/pager.html" . }}
{{ partial "components/comment.html" . }}
{{ partial "components/comments.html" . }}
</main>
</article>
</div>
Expand Down
2 changes: 1 addition & 1 deletion layouts/docs/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h1>{{ .Title }}</h1>
</div>
{{ partial "components/last-updated.html" . }}
{{ partial "components/pager.html" . }}
{{ partial "components/comment.html" . }}
{{ partial "components/comments.html" . }}
</main>
</article>
</div>
Expand Down
8 changes: 0 additions & 8 deletions layouts/partials/components/comment.html

This file was deleted.

11 changes: 11 additions & 0 deletions layouts/partials/components/comments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- $enableComments := site.Params.comments.enable | default false -}}

{{ if not (eq .Params.comments nil) }}
{{ $enableComments = .Params.comments }}
{{ end }}

{{- if $enableComments -}}
{{- if eq site.Params.comments.type "giscus" -}}
{{ partial "components/giscus.html" . }}
{{- end -}}
{{- end -}}
4 changes: 3 additions & 1 deletion layouts/partials/components/giscus.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- $lang := site.Language.LanguageCode | default `en` -}}

{{- with site.Params.comment.giscus -}}
{{- with site.Params.comments.giscus -}}
<script>
/*
* "preferred color scheme" theme in giscus works using "prefers-color-scheme" in media query.
Expand Down Expand Up @@ -57,4 +57,6 @@
</script>

<div id="giscus"></div>
{{- else -}}
{{ warnf "giscus is not configured" }}
{{- end -}}

0 comments on commit 46dea71

Please sign in to comment.