diff options
Diffstat (limited to 'themes/hugo-theme-stack/layouts/partials/comments/provider/utterances.html')
-rw-r--r-- | themes/hugo-theme-stack/layouts/partials/comments/provider/utterances.html | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/themes/hugo-theme-stack/layouts/partials/comments/provider/utterances.html b/themes/hugo-theme-stack/layouts/partials/comments/provider/utterances.html new file mode 100644 index 0000000..b1e370b --- /dev/null +++ b/themes/hugo-theme-stack/layouts/partials/comments/provider/utterances.html @@ -0,0 +1,46 @@ +<script src="https://utteranc.es/client.js" + repo="{{ .Site.Params.comments.utterances.repo }}" + issue-term="{{ .Site.Params.comments.utterances.issueTerm }}" + {{ with .Site.Params.comments.utterances.label }} + label="{{ . }}" + {{ end }} + crossorigin="anonymous" + async + > +</script> + +<style> + .utterances { + max-width: unset; + } +</style> + +<script> + let utterancesLoaded = false; + + function setUtterancesTheme(theme) { + let utterances = document.querySelector('.utterances iframe'); + if (utterances) { + utterances.contentWindow.postMessage( + { + type: 'set-theme', + theme: `github-${theme}` + }, + 'https://utteranc.es' + ); + } + } + + addEventListener('message', event => { + if (event.origin !== 'https://utteranc.es') return; + + /// Called when Utterances is ready + utterancesLoaded = true; + setUtterancesTheme(document.documentElement.dataset.scheme) + }); + + window.addEventListener('onColorSchemeChange', (e) => { + if (!utterancesLoaded) return; + setUtterancesTheme(e.detail) + }) +</script> |