fix: giscus theme and language display issues (#95)

* chore: minor update giscus template

* fix: theme toggle should select all

* chore: example configs for giscus

* fix: language code in giscus
This commit is contained in:
Xin 2023-09-26 22:12:38 +01:00 committed by GitHub
parent 6a19ac31c0
commit adf5a113fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 8 deletions

View File

@ -26,6 +26,7 @@ languages:
title: "Hextra テーマ"
zh-cn:
languageName: 简体中文
languageCode: zh-CN
weight: 3
title: Hextra
@ -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"

View File

@ -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.
@ -40,9 +40,6 @@
"data-theme": getGiscusTheme(),
"data-lang": "{{ .lang | default $lang }}",
"crossorigin": "anonymous",
{{ if .lazyLoading -}}
"data-loading": "lazy",
{{ end -}}
"async": "",
};
@ -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 -}}