simoncor.net/themes/hugo-coder/layouts/partials/posts/utterances.html

32 lines
1.2 KiB
HTML
Raw Permalink Normal View History

2020-07-16 22:43:30 +02:00
{{- if isset .Site.Params "utterances" -}}
2024-08-26 17:13:18 +02:00
{{- 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");
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';
s.setAttribute('repo', '{{ .Site.Params.utterances.repo }}');
s.setAttribute('issue-term', '{{ default "title" .Site.Params.utterances.issueTerm }}');
s.setAttribute('theme', theme);
s.setAttribute('crossorigin', 'anonymous');
s.setAttribute('async', '');
document.querySelector('div.comments').innerHTML = '';
document.querySelector('div.comments').appendChild(s);
2020-07-16 22:43:30 +02:00
</script>
2024-08-26 17:13:18 +02:00
</div>
2020-07-16 22:43:30 +02:00
{{- end -}}
2024-08-26 17:13:18 +02:00
{{- end -}}