diff options
author | Jimmy Cai <jimmehcai@gmail.com> | 2021-02-11 20:46:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-11 20:46:23 +0300 |
commit | a8718592dfce06452ffd66dc544777e71b4a2782 (patch) | |
tree | 1ea0bac4c1899b8b785edb32c2d7f0e1a0dae043 | |
parent | 70cc14fcbe9e229fef7dc2c6a861f1bd6d3c647e (diff) |
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
-rw-r--r-- | exampleSite/config.yaml | 1 | ||||
-rw-r--r-- | layouts/partials/comments/provider/utterances.html | 19 |
2 files changed, 14 insertions, 6 deletions
diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index fb89f51..515c97c 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -50,7 +50,6 @@ params: repo: issueTerm: pathname label: - theme: preferred-color-scheme widgets: enabled: diff --git a/layouts/partials/comments/provider/utterances.html b/layouts/partials/comments/provider/utterances.html index e2ecf6d..a0c07a6 100644 --- a/layouts/partials/comments/provider/utterances.html +++ b/layouts/partials/comments/provider/utterances.html @@ -1,12 +1,12 @@ <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> + crossorigin="anonymous" + async + > </script> <style> @@ -16,16 +16,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>
\ No newline at end of file |