Skip to content

Commit

Permalink
fix(giscus): fallback to en language if site language is unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Jul 23, 2022
1 parent 9d5df11 commit fe1fb5f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ viewer = true # Image Viewer
# inputPosition = "bottom" # Default to top.
# reactions = false # Disable reactions.
# metadata = true # Emit discussion metadata.
# lang = "" # Specify language, default to site language.
# lang = "en" # Specify language, default to site language.

[search]
paginate = 5 # Pagination. Default to 10.
Expand Down
7 changes: 6 additions & 1 deletion layouts/partials/post/comments/giscus.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{{- with .Site.Params.giscus }}
{{- $langs := dict "zh-hans" "zh-CN" "zh-hant" "zh-TW" -}}
{{- $langs := dict "zh-cn" "zh-CN" "zh-tw" "zh-TW" "zh-hk" "zh-TW" "zh-hans" "zh-CN" "zh-hant" "zh-TW" -}}
{{- $validLangs := slice "de" "gsw" "es" "fr" "id" "it" "ja" "ko" "pl" "pt" "ro" "ru" "tr" "vi" "zh-CN" "zh-TW" -}}
{{- $lang := default $.Site.Language.Lang .lang }}
{{- with index $langs $lang }}{{ $lang = . }}{{ end }}
{{- if not (in $validLangs $lang) }}
{{- warnf "[giscus] lang %q is unsupported, fallback to %q" $lang "en" }}
{{- $lang = "en" }}
{{- end }}
<script src="https://giscus.app/client.js"
data-repo="{{ .repo }}"
data-repo-id="{{ .repoId }}"
Expand Down

0 comments on commit fe1fb5f

Please sign in to comment.