Skip to content

Commit

Permalink
fix: wrong utterances theme after theme is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
reuixiy committed Dec 23, 2019
1 parent 8339f71 commit 4389ddf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assets/js/dark-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function changeMode() {

// Utterances
// https://github.com/utterance/utterances/issues/229
{{ if .Site.Params.enableUtterances }}
{{ if and .Site.Params.enableUtterances (eq hugo.Environment "production") }}
if (arguments[0] === "🌙") {
changeUtterancesTheme("{{ .Site.Params.utterancesThemeDark }}");
} else {
Expand Down
3 changes: 3 additions & 0 deletions layouts/partials/third-party/utterances.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
{{- $Deliver := .Deliver -}}
{{- $theme := .theme -}}
{{- if $Deliver.Site.Params.enableDarkMode -}}
const userPrefers = localStorage.getItem('theme');
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
const lightModeMediaQuery = window.matchMedia('(prefers-color-scheme: light)');
if (userPrefers === "dark") {
script.setAttribute('theme', '{{ $Deliver.Site.Params.utterancesThemeDark }}');
} else if (userPrefers === "light") {
Expand Down

0 comments on commit 4389ddf

Please sign in to comment.