dynamic change utterances theme with coder theme (#676)

* dynamic change utterances theme with coder theme

* add myself into CONTRIBUTORS.md
This commit is contained in:
Zhan Shuo
2022-05-30 02:38:59 +08:00
committed by GitHub
parent 40eeed8256
commit 9ea82c5c82
3 changed files with 63 additions and 8 deletions

View File

@@ -1,12 +1,24 @@
{{- if isset .Site.Params "utterances" -}}
{{- if and (isset .Site.Params.utterances "repo") (not (eq .Site.Params.utterances.repo "" )) (eq (.Params.disableComments | default false) false) -}}
<script src="https://utteranc.es/client.js"
repo= "{{ .Site.Params.utterances.repo }}"
issue-term="{{ default "title" .Site.Params.utterances.issueTerm }}"
{{ if isset .Site.Params.utterances "label" }}label="{{ .Site.Params.utterances.label }}"{{ end }}
theme="{{ default "github-light" .Site.Params.utterances.theme }}"
crossorigin="anonymous"
async>
</script>
<div class="comments">
<script>
let getTheme = window.localStorage && window.localStorage.getItem("colorscheme");
getTheme = getTheme == null ? '{{$.Site.Params.utterances.theme}}' : getTheme;
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);
</script>
</div>
{{- end -}}
{{- end -}}