1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2026-06-21 23:38:39 +00:00
Files
Cotes Chung 7496dd41fa feat(theme): persist user theme preferences (#2756)
- Migrate theme persistence from `sessionStorage` to `localStorage`
- Rename theme HTML attribute to `data-bs-theme` for Bootstrap compatibility
- Trim and compile CSS according to the chosen theme mode
2026-06-17 23:20:12 +08:00

39 lines
1.3 KiB
HTML

<!-- https://utteranc.es/ -->
<script>
(function () {
const origin = 'https://utteranc.es';
const themeMap = Theme.newThemeMap('github-light', 'github-dark');
const initTheme = themeMap[Theme.resolvedTheme];
let script = document.createElement('script');
script.src = 'https://utteranc.es/client.js';
script.setAttribute('repo', '{{ site.comments.utterances.repo }}');
script.setAttribute('issue-term', '{{ site.comments.utterances.issue_term }}');
script.setAttribute('theme', initTheme);
script.crossOrigin = 'anonymous';
script.async = true;
const $footer = document.querySelector('footer');
$footer.insertAdjacentElement('beforebegin', script);
addEventListener('message', (event) => {
let newTheme;
{%- comment -%}
Credit to <https://github.com/utterance/utterances/issues/170#issuecomment-594036347>
{%- endcomment -%}
if (event.source === window && event.data && event.data.id === Theme.eventId) {
newTheme = themeMap[Theme.resolvedTheme];
const message = {
type: 'set-theme',
theme: newTheme
};
const utterances = document.querySelector('.utterances-frame').contentWindow;
utterances.postMessage(message, origin);
}
});
})();
</script>