From 0709854dc8f6099d38c2578967a02f73b4be0dc8 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sun, 16 Jun 2024 22:25:41 +0800 Subject: [PATCH] fix: adapt the giscus localization parameter (#1810) --- _includes/comments/giscus.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/_includes/comments/giscus.html b/_includes/comments/giscus.html index c8d48e6..f9becfe 100644 --- a/_includes/comments/giscus.html +++ b/_includes/comments/giscus.html @@ -17,6 +17,12 @@ initTheme = darkTheme; } + let lang = '{{ site.comments.giscus.lang | default: lang }}'; + {%- comment -%} https://github.com/giscus/giscus/tree/main/locales {%- endcomment -%} + if (lang.length > 2 && !lang.startsWith('zh')) { + lang = lang.slice(0, 2); + } + let giscusAttributes = { src: 'https://giscus.app/client.js', 'data-repo': '{{ site.comments.giscus.repo}}', @@ -29,7 +35,7 @@ 'data-emit-metadata': '0', 'data-theme': initTheme, 'data-input-position': '{{ site.comments.giscus.input_position | default: 'bottom' }}', - 'data-lang': '{{ site.comments.giscus.lang | default: lang }}', + 'data-lang': lang, 'data-loading': 'lazy', crossorigin: 'anonymous', async: ''