From aeb0cad979a647fded2c8b51bd839634e8c3916f Mon Sep 17 00:00:00 2001 From: Robb Shecter Date: Mon, 15 Apr 2024 18:53:10 -0600 Subject: [PATCH] Special case for Chinese --- layouts/partials/components/giscus.html | 26 +++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/layouts/partials/components/giscus.html b/layouts/partials/components/giscus.html index 4a2e960..d377ebb 100644 --- a/layouts/partials/components/giscus.html +++ b/layouts/partials/components/giscus.html @@ -1,4 +1,26 @@ -{{- $lang := site.Language.Lang | default `en` -}} +{{ $default_chinese := "zh-CN" }} + +{{ $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" }} + {{/* 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 -}}