fix(utterances): set color scheme on load

Remove utterances.theme option from config.yaml
This commit is contained in:
Jimmy Cai 2021-02-11 18:43:39 +01:00
parent 70cc14fcbe
commit 6358ea3db5
No known key found for this signature in database
GPG Key ID: 3EA408E527F37B18
2 changed files with 12 additions and 5 deletions

View File

@ -50,7 +50,6 @@ params:
repo:
issueTerm: pathname
label:
theme: preferred-color-scheme
widgets:
enabled:

View File

@ -1,12 +1,11 @@
<script src="https://utteranc.es/client.js"
repo="{{ .Site.Params.comments.utterances.repo }}"
issue-term="{{ .Site.Params.comments.utterances.issueTerm }}"
theme="{{ .Site.Params.comments.utterances.theme }}"
{{ with .Site.Params.comments.utterances.label }}
label="{{ . }}"
{{ end }}
crossorigin="anonymous"
async>
>
</script>
<style>
@ -16,16 +15,25 @@
</style>
<script>
window.addEventListener('onColorSchemeChange', (e) => {
function setUtterancesTheme(theme) {
let utterances = document.querySelector('.utterances iframe');
if (utterances) {
utterances.contentWindow.postMessage(
{
type: 'set-theme',
theme: `github-${e.detail}`
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>