Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: giscus.html fails when country code is specified. #358

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions layouts/partials/components/giscus.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
{{- $lang := site.Language.LanguageCode | default `en` -}}
{{ $default_chinese := "zh-CN" }}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just inline this $default_chinese, or move it inside the if block?


{{ $sl := site.Language }}
{{ $giscus_lang := $sl.Lang | default `en` }}

{{/*
Special case for Chinese.
Giscus uses the geophraphical language code for these.
See: https://github.com/giscus/giscus/tree/main/locales
*/}}
{{ if eq $giscus_lang "zh" }}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, $giscus_lang could also be zh-cn, so it's better to use hasPrefix instead of eq.

{{/* Create a code formatted for Giscus: zh-CN or zn-TW. */}}
{{ $code := lower $sl.LanguageCode }}

{{ if (hasSuffix $code "-cn") }}
{{ $giscus_lang = "zh-CN" }}
{{ else if (hasSuffix $code "-tw") }}
{{ $giscus_lang = "zh-TW" }}
{{ else }}
{{ $giscus_lang = $default_chinese }}
{{ end }}
{{ end }}


{{- with site.Params.comments.giscus -}}
<script>
Expand Down Expand Up @@ -38,7 +60,7 @@
"data-emit-metadata": "{{ (string .emitMetadata) | default 0 }}",
"data-input-position": "{{ .inputPosition | default `top` }}",
"data-theme": getGiscusTheme(),
"data-lang": "{{ .lang | default $lang }}",
"data-lang": "{{ .lang | default $giscus_lang }}",
"crossorigin": "anonymous",
"async": "",
};
Expand Down