fix: make Disqus / Utterances follow the global color scheme (#111)

* fix: make Disqus / Utterances follow the global color scheme

* fix: check if DISQUS exists before executing DISQUS.reset

closes https://github.com/CaiJimmy/hugo-theme-stack/issues/107
This commit is contained in:
Jimmy Cai 2021-01-01 13:32:19 +01:00 committed by GitHub
parent 2ee854dd6a
commit 84dd80959a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -10,3 +10,13 @@
padding: var(--card-padding);
}
</style>
<script>
window.addEventListener('onColorSchemeChange', (e) => {
if (DISQUS) {
DISQUS.reset({
reload: true
});
}
})
</script>

View file

@ -13,4 +13,19 @@
.utterances {
max-width: unset;
}
</style>
</style>
<script>
window.addEventListener('onColorSchemeChange', (e) => {
let utterances = document.querySelector('.utterances iframe');
if (utterances) {
utterances.contentWindow.postMessage(
{
type: 'set-theme',
theme: `github-${e.detail}`
},
'https://utteranc.es'
);
}
})
</script>