From e35f1da207cb25f4fce730177423d041cf90e7dd Mon Sep 17 00:00:00 2001
From: Piotr Kozerski <piotrek-k@users.noreply.github.com>
Date: Thu, 24 Aug 2023 20:01:07 +0000
Subject: [PATCH] Fixing problem with incorrect style of utterances comment section (#840)

---
 layouts/partials/posts/utterances.html |   31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/layouts/partials/posts/utterances.html b/layouts/partials/posts/utterances.html
index f929cbd..5388cf6 100644
--- a/layouts/partials/posts/utterances.html
+++ b/layouts/partials/posts/utterances.html
@@ -1,12 +1,21 @@
 {{- if isset .Site.Params "utterances" -}}
-  {{- if and (isset .Site.Params.utterances "repo") (not (eq .Site.Params.utterances.repo "" )) (eq (.Params.disableComments | default false) false) -}}
-  <div class="comments">
-    <script>
-  
+{{- if and (isset .Site.Params.utterances "repo") (not (eq .Site.Params.utterances.repo "" )) (eq
+(.Params.disableComments | default false) false) -}}
+<div class="comments">
+  <script>
+
     let getTheme = window.localStorage && window.localStorage.getItem("colorscheme");
-  
-    getTheme = getTheme == null ? '{{$.Site.Params.utterances.theme}}' : getTheme;
-    
+    let themeInParams = '{{$.Site.Params.utterances.theme}}';
+
+    if (getTheme == null) {
+      if (themeInParams !== '' && themeInParams !== 'auto') {
+        getTheme = themeInParams;
+      }
+      else {
+        getTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? "dark" : "light";
+      }
+    }
+
     let theme = getTheme === 'dark' ? 'github-dark' : 'github-light';
     let s = document.createElement('script');
     s.src = 'https://utteranc.es/client.js';
@@ -17,8 +26,8 @@
     s.setAttribute('async', '');
     document.querySelector('div.comments').innerHTML = '';
     document.querySelector('div.comments').appendChild(s);
-  
-    </script>
-    </div>
-  {{- end -}}
+
+  </script>
+</div>
 {{- end -}}
+{{- end -}}
\ No newline at end of file

--
Gitblit v1.10.0