utterances.html 1.2 KB

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