1
0

utterances.html 1.2 KB

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