Hugo-theme-stack/layouts/partials/comments/provider/utterances.html
Jimmy Cai a8718592df
fix(utterances): set color scheme on load (#138)
* fix(utterances): set color scheme on load

Remove utterances.theme option from config.yaml

* fix(utterances): restore async tag
2021-02-11 18:46:23 +01:00

40 lines
1.1 KiB
HTML

<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>
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;
setUtterancesTheme(document.body.dataset.scheme)
});
window.addEventListener('onColorSchemeChange', (e) => {
setUtterancesTheme(e.detail)
})
</script>