From 9a041c151c9e614ec86bb42f0d65e5c7c2f0e5a9 Mon Sep 17 00:00:00 2001 From: reuixiy Date: Wed, 24 Jun 2020 18:51:06 +0800 Subject: [PATCH] fix: wrong utterances theme When current theme is different from `defaultTheme`, it still gets `defaultTheme`, instead of current theme. --- layouts/partials/third-party/utterances.html | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/layouts/partials/third-party/utterances.html b/layouts/partials/third-party/utterances.html index 94a12d81..5f667dd7 100644 --- a/layouts/partials/third-party/utterances.html +++ b/layouts/partials/third-party/utterances.html @@ -8,7 +8,7 @@ script.crossOrigin = 'anonymous'; script.setAttribute('repo', '{{ .Site.Params.utterancesRepo }}'); script.setAttribute('issue-term', '{{ .Site.Params.utterancesIssueTerm }}'); - script.setAttribute('theme', '{{ template "utterances-theme" . }}'); + {{ template "utterances-theme" . }} {{ with .Site.Params.utterancesLabel }} script.setAttribute('label', '{{ . }}'); {{ end }} @@ -22,5 +22,15 @@ {{- if and .Site.Params.enableDarkMode (eq .Site.Params.defaultTheme "dark") -}} {{- $theme = .Site.Params.utterancesThemeDark | default "photon-dark" -}} {{- end -}} - {{- $theme -}} + + {{- if .Site.Params.enableDarkMode -}} + const isDark = getCurrentTheme() === 'dark'; + if (isDark) { + script.setAttribute('theme', '{{ .Site.Params.utterancesThemeDark | default "photon-dark" }}'); + } else { + script.setAttribute('theme', '{{ .Site.Params.utterancesTheme | default "github-light" }}'); + } + {{- else -}} + script.setAttribute('theme', '{{ $theme }}'); + {{- end -}} {{- end -}}