Skip to content

Commit

Permalink
fix: giscus theme and language display issues (#95)
Browse files Browse the repository at this point in the history
* chore: minor update giscus template

* fix: theme toggle should select all

* chore: example configs for giscus

* fix: language code in giscus
  • Loading branch information
imfing authored Sep 26, 2023
1 parent 6a19ac3 commit adf5a11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
18 changes: 18 additions & 0 deletions exampleSite/hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ languages:
title: "Hextra テーマ"
zh-cn:
languageName: 简体中文
languageCode: zh-CN
weight: 3
title: Hextra

Expand Down Expand Up @@ -122,3 +123,20 @@ params:
editURL:
enable: true
base: "https://github.com/imfing/hextra/edit/main/exampleSite/content"

comment:
enable: false
type: giscus

# https://giscus.app/
giscus:
repo: "imfing/hextra"
repoId: "R_kgDOJ9fJag"
category: "General"
categoryId: "DIC_kwDOJ9fJas4CY7gW"
# mapping: "pathname"
# strict: 0
# reactionsEnabled: 1
# emitMetadata: 0
# inputPosition: "top"
# lang: "en"
14 changes: 6 additions & 8 deletions layouts/partials/components/giscus.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- with site.Params.comment.giscus -}}
{{- $lang := site.Language.LanguageCode | default `en` -}}

{{- $lang = site.Language.Lang | default `en` -}}
{{- with site.Params.comment.giscus -}}
<script>
/*
* "preferred color scheme" theme in giscus works using "prefers-color-scheme" in media query.
Expand Down Expand Up @@ -40,9 +40,6 @@
"data-theme": getGiscusTheme(),
"data-lang": "{{ .lang | default $lang }}",
"crossorigin": "anonymous",
{{ if .lazyLoading -}}
"data-loading": "lazy",
{{ end -}}
"async": "",
};

Expand All @@ -52,11 +49,12 @@
document.getElementById('giscus').appendChild(giscusScript);

// Update giscus theme when theme switcher is clicked
const toggle = document.querySelector('.theme-toggle');
if (toggle) {
toggle.addEventListener('click', setGiscusTheme);
const toggles = document.querySelectorAll(".theme-toggle");
if (toggles) {
toggles.forEach(toggle => toggle.addEventListener('click', setGiscusTheme));
}
});
</script>

<div id="giscus"></div>
{{- end -}}

0 comments on commit adf5a11

Please sign in to comment.