utterances.html (1233B)
1 {{- if isset .Site.Params "utterances" -}} 2 {{- if and (isset .Site.Params.utterances "repo") (not (eq .Site.Params.utterances.repo "" )) (eq (.Params.disableComments | default false) false) -}} 3 <div class="comments"> 4 <script> 5 6 let getTheme = window.localStorage && window.localStorage.getItem("colorscheme"); 7 let themeInParams = '{{$.Site.Params.utterances.theme}}'; 8 9 if (getTheme == null) { 10 if (themeInParams !== '' && themeInParams !== 'auto') { 11 getTheme = themeInParams; 12 } 13 else { 14 getTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? "dark" : "light"; 15 } 16 } 17 18 let theme = getTheme === 'dark' ? 'github-dark' : 'github-light'; 19 let s = document.createElement('script'); 20 s.src = 'https://utteranc.es/client.js'; 21 s.setAttribute('repo', '{{ .Site.Params.utterances.repo }}'); 22 s.setAttribute('issue-term', '{{ default "title" .Site.Params.utterances.issueTerm }}'); 23 s.setAttribute('theme', theme); 24 s.setAttribute('crossorigin', 'anonymous'); 25 s.setAttribute('async', ''); 26 document.querySelector('div.comments').innerHTML = ''; 27 document.querySelector('div.comments').appendChild(s); 28 29 </script> 30 </div> 31 {{- end -}} 32 {{- end -}}