mirror of
https://github.com/cotes2020/jekyll-theme-chirpy.git
synced 2026-06-21 23:38:39 +00:00
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
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
{%- comment -%} Auto switch theme {%- endcomment -%}
|
||||
function reloadDisqus(event) {
|
||||
if (event.source === window && event.data && event.data.id === Theme.ID) {
|
||||
if (event.source === window && event.data && event.data.id === Theme.eventId) {
|
||||
{%- comment -%} Disqus hasn't been loaded {%- endcomment -%}
|
||||
if (typeof DISQUS === 'undefined') {
|
||||
return;
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
addDisqus();
|
||||
|
||||
if (Theme.switchable) {
|
||||
if (Theme.isToggleable) {
|
||||
addEventListener('message', reloadDisqus);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<!-- https://giscus.app/ -->
|
||||
<script>
|
||||
(function () {
|
||||
const themeMapper = Theme.getThemeMapper('light', 'dark_dimmed');
|
||||
const initTheme = themeMapper[Theme.visualState];
|
||||
const themeMap = Theme.newThemeMap('light', 'dark_dimmed');
|
||||
const initTheme = themeMap[Theme.resolvedTheme];
|
||||
|
||||
let lang = '{{ site.comments.giscus.lang | default: lang }}';
|
||||
{%- comment -%} https://github.com/giscus/giscus/tree/main/locales {%- endcomment -%}
|
||||
@@ -37,8 +37,9 @@
|
||||
$footer.insertAdjacentElement("beforebegin", giscusNode);
|
||||
|
||||
addEventListener('message', (event) => {
|
||||
if (event.source === window && event.data && event.data.id === Theme.ID) {
|
||||
const newTheme = themeMapper[Theme.visualState];
|
||||
if (event.source === window && event.data && event.data.id === Theme.eventId) {
|
||||
const newTheme = themeMap[Theme.resolvedTheme];
|
||||
|
||||
const message = {
|
||||
setConfig: {
|
||||
theme: newTheme
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<script>
|
||||
(function () {
|
||||
const origin = 'https://utteranc.es';
|
||||
const themeMapper = Theme.getThemeMapper('github-light', 'github-dark');
|
||||
const initTheme = themeMapper[Theme.visualState];
|
||||
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';
|
||||
@@ -22,8 +22,8 @@
|
||||
{%- comment -%}
|
||||
Credit to <https://github.com/utterance/utterances/issues/170#issuecomment-594036347>
|
||||
{%- endcomment -%}
|
||||
if (event.source === window && event.data && event.data.id === Theme.ID) {
|
||||
newTheme = themeMapper[Theme.visualState];
|
||||
if (event.source === window && event.data && event.data.id === Theme.eventId) {
|
||||
newTheme = themeMap[Theme.resolvedTheme];
|
||||
|
||||
const message = {
|
||||
type: 'set-theme',
|
||||
|
||||
Reference in New Issue
Block a user