From 7496dd41fa053c4636a82027fe3fb3e38357e385 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Wed, 17 Jun 2026 23:20:12 +0800 Subject: [PATCH] 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 --- _data/locales/ar.yml | 5 + _data/locales/bg-BG.yml | 5 + _data/locales/ca-ES.yml | 5 + _data/locales/cs-CZ.yml | 5 + _data/locales/da-DK.yml | 5 + _data/locales/de-DE.yml | 5 + _data/locales/dv‑MV.yml | 5 + _data/locales/el-GR.yml | 5 + _data/locales/en.yml | 5 + _data/locales/es-ES.yml | 5 + _data/locales/fa-IR.yml | 5 + _data/locales/fi-FI.yml | 5 + _data/locales/fr-FR.yml | 5 + _data/locales/hu-HU.yml | 5 + _data/locales/id-ID.yml | 5 + _data/locales/it-IT.yml | 5 + _data/locales/ja-JP.yml | 5 + _data/locales/ko-KR.yml | 5 + _data/locales/ku-IQ.yml | 5 + _data/locales/my-MM.yml | 5 + _data/locales/nl-NL.yml | 5 + _data/locales/ps‑AF.yml | 5 + _data/locales/pt-BR.yml | 5 + _data/locales/ru-RU.yml | 5 + _data/locales/sl-SI.yml | 5 + _data/locales/sv-SE.yml | 5 + _data/locales/th.yml | 5 + _data/locales/tr-TR.yml | 5 + _data/locales/uk-UA.yml | 5 + _data/locales/ur-PK.yml | 5 + _data/locales/vi-VN.yml | 5 + _data/locales/zh-CN.yml | 5 + _data/locales/zh-TW.yml | 5 + _data/origin/cors.yml | 3 + _includes/comments/disqus.html | 4 +- _includes/comments/giscus.html | 9 +- _includes/comments/utterances.html | 8 +- _includes/head.html | 2 +- _includes/sidebar.html | 52 ++++- _javascript/modules/components/img-popup.js | 10 +- _javascript/modules/components/mermaid.js | 14 +- _javascript/modules/components/mode-toggle.js | 41 +++- _javascript/theme.js | 196 ++++++++++-------- _layouts/default.html | 11 +- _sass/abstracts/_mixins.scss | 6 + _sass/abstracts/_variables.scss | 6 + _sass/base/_base.scss | 43 ++-- _sass/layout/_sidebar.scss | 102 ++++++++- _sass/themes/_dark.scss | 9 +- _sass/themes/_light.scss | 9 +- assets/css/jekyll-theme-chirpy.scss | 4 + 51 files changed, 541 insertions(+), 153 deletions(-) diff --git a/_data/locales/ar.yml b/_data/locales/ar.yml index 78e6f9427..7a10aa151 100644 --- a/_data/locales/ar.yml +++ b/_data/locales/ar.yml @@ -49,6 +49,11 @@ notification: update_found: يتوفر اصدار جديد للمحتوى. update: تحديث +theme: + light: فاتح + dark: داكن + system: النظام + # ----- Posts related labels ----- post: diff --git a/_data/locales/bg-BG.yml b/_data/locales/bg-BG.yml index 5b50a3ee2..1c8ab32e9 100644 --- a/_data/locales/bg-BG.yml +++ b/_data/locales/bg-BG.yml @@ -49,6 +49,11 @@ notification: update_found: Налична е нова версия на съдържанието. update: Обнови +theme: + light: Светла + dark: Тъмна + system: Системна + # ----- Posts related labels ----- post: diff --git a/_data/locales/ca-ES.yml b/_data/locales/ca-ES.yml index 7e68f451c..ea0ea130b 100644 --- a/_data/locales/ca-ES.yml +++ b/_data/locales/ca-ES.yml @@ -49,6 +49,11 @@ notification: update_found: Hi ha una nova versió de contingut disponible. update: Actualitzar +theme: + light: Clar + dark: Fosc + system: Sistema + # ----- Posts related labels ----- post: diff --git a/_data/locales/cs-CZ.yml b/_data/locales/cs-CZ.yml index 41b31d61f..a2689efdd 100644 --- a/_data/locales/cs-CZ.yml +++ b/_data/locales/cs-CZ.yml @@ -49,6 +49,11 @@ notification: update_found: Je k dispozici nová verze obsahu. update: Aktualizace +theme: + light: Světlý + dark: Tmavý + system: Systém + # ----- Posts related labels ----- post: diff --git a/_data/locales/da-DK.yml b/_data/locales/da-DK.yml index 3b841750c..73c350343 100644 --- a/_data/locales/da-DK.yml +++ b/_data/locales/da-DK.yml @@ -49,6 +49,11 @@ notification: update_found: En ny version af indholdet er fundet! update: Opdater +theme: + light: Lys + dark: Mørk + system: System + # ----- Posts related labels ----- post: diff --git a/_data/locales/de-DE.yml b/_data/locales/de-DE.yml index 8e26b617a..fe5940b0f 100644 --- a/_data/locales/de-DE.yml +++ b/_data/locales/de-DE.yml @@ -48,6 +48,11 @@ notification: update_found: Eine neue Version ist verfügbar. update: Neue Version +theme: + light: Hell + dark: Dunkel + system: System + # ----- Posts related labels ----- post: diff --git a/_data/locales/dv‑MV.yml b/_data/locales/dv‑MV.yml index a808fd611..a0158c852 100644 --- a/_data/locales/dv‑MV.yml +++ b/_data/locales/dv‑MV.yml @@ -49,6 +49,11 @@ notification: update_found: ޔޫ ވާރޝަން ހުރިހާ. update: އޮޕްޑޭޓް +theme: + light: އަލި + dark: އަނދިރި + system: ސިސްޓަމް + # ----- Posts related labels ----- post: diff --git a/_data/locales/el-GR.yml b/_data/locales/el-GR.yml index 48d25f743..5df549e97 100644 --- a/_data/locales/el-GR.yml +++ b/_data/locales/el-GR.yml @@ -49,6 +49,11 @@ notification: update_found: Υπάρχει διαθέσιμη μια νέα έκδοση του περιεχομένου. update: Ενημέρωση +theme: + light: Φωτεινό + dark: Σκοτεινό + system: Σύστημα + # ----- Posts related labels ----- post: diff --git a/_data/locales/en.yml b/_data/locales/en.yml index d35362e02..e453b121b 100644 --- a/_data/locales/en.yml +++ b/_data/locales/en.yml @@ -49,6 +49,11 @@ notification: update_found: A new version of content is available. update: Update +theme: + light: Light + dark: Dark + system: System + # ----- Posts related labels ----- post: diff --git a/_data/locales/es-ES.yml b/_data/locales/es-ES.yml index d989b5b51..a8390c372 100644 --- a/_data/locales/es-ES.yml +++ b/_data/locales/es-ES.yml @@ -49,6 +49,11 @@ notification: update_found: Hay una nueva versión de contenido disponible. update: Actualizar +theme: + light: Claro + dark: Oscuro + system: Sistema + # ----- Posts related labels ----- post: diff --git a/_data/locales/fa-IR.yml b/_data/locales/fa-IR.yml index 0d990a8ee..6cc27cd02 100644 --- a/_data/locales/fa-IR.yml +++ b/_data/locales/fa-IR.yml @@ -49,6 +49,11 @@ notification: update_found: نسخه جدیدی از محتوا موجود است. update: به‌روزرسانی +theme: + light: روشن + dark: تیره + system: سیستم + # ----- Posts related labels ----- post: diff --git a/_data/locales/fi-FI.yml b/_data/locales/fi-FI.yml index b8b1c196f..889ac7215 100644 --- a/_data/locales/fi-FI.yml +++ b/_data/locales/fi-FI.yml @@ -48,6 +48,11 @@ notification: update_found: Uusi versio sisällöstä on saatavilla. update: Päivitä +theme: + light: Vaalea + dark: Tumma + system: Järjestelmä + # ----- Posts related labels ----- post: diff --git a/_data/locales/fr-FR.yml b/_data/locales/fr-FR.yml index c4884c3c9..2925a7412 100644 --- a/_data/locales/fr-FR.yml +++ b/_data/locales/fr-FR.yml @@ -49,6 +49,11 @@ notification: update_found: Une nouvelle version du contenu est disponible. update: Mise à jour +theme: + light: Clair + dark: Sombre + system: Système + # ----- Posts related labels ----- post: diff --git a/_data/locales/hu-HU.yml b/_data/locales/hu-HU.yml index 3c379f658..a14756b78 100644 --- a/_data/locales/hu-HU.yml +++ b/_data/locales/hu-HU.yml @@ -50,6 +50,11 @@ notification: update_found: Elérhető a tartalom új verziója. update: Frissítés +theme: + light: Világos + dark: Sötét + system: Rendszer + # ----- Posts related labels ----- post: diff --git a/_data/locales/id-ID.yml b/_data/locales/id-ID.yml index 337e4c008..0f1bb2f9e 100644 --- a/_data/locales/id-ID.yml +++ b/_data/locales/id-ID.yml @@ -49,6 +49,11 @@ notification: update_found: Versi konten baru tersedia. update: Perbarui +theme: + light: Terang + dark: Gelap + system: Sistem + # ----- Posts related labels ----- post: diff --git a/_data/locales/it-IT.yml b/_data/locales/it-IT.yml index e1137a996..671ff1ca5 100644 --- a/_data/locales/it-IT.yml +++ b/_data/locales/it-IT.yml @@ -48,6 +48,11 @@ notification: update_found: Nuova versione del contenuto disponibile. update: Aggiornamento +theme: + light: Chiaro + dark: Scuro + system: Sistema + # ----- Posts related labels ----- post: diff --git a/_data/locales/ja-JP.yml b/_data/locales/ja-JP.yml index 68891dcb1..c271e3326 100644 --- a/_data/locales/ja-JP.yml +++ b/_data/locales/ja-JP.yml @@ -49,6 +49,11 @@ notification: update_found: 新しいバージョンが利用可能です。 update: 更新 +theme: + light: ライト + dark: ダーク + system: システム + # ----- Posts related labels ----- post: diff --git a/_data/locales/ko-KR.yml b/_data/locales/ko-KR.yml index ed45a75c0..48af8bc27 100644 --- a/_data/locales/ko-KR.yml +++ b/_data/locales/ko-KR.yml @@ -49,6 +49,11 @@ notification: update_found: 새 버전의 콘텐츠를 사용할 수 있습니다. update: 업데이트 +theme: + light: 라이트 + dark: 다크 + system: 시스템 + # ----- Posts related labels ----- post: diff --git a/_data/locales/ku-IQ.yml b/_data/locales/ku-IQ.yml index 61cd3cd21..1d809b81e 100644 --- a/_data/locales/ku-IQ.yml +++ b/_data/locales/ku-IQ.yml @@ -49,6 +49,11 @@ notification: update_found: وەشانێکی نوێی ناوەڕۆک بەردەستە. update: نوێکردنەوە +theme: + light: ڕووناک + dark: تاریک + system: سیستەم + # ----- Posts related labels ----- post: diff --git a/_data/locales/my-MM.yml b/_data/locales/my-MM.yml index 5559aea0a..e497636ba 100644 --- a/_data/locales/my-MM.yml +++ b/_data/locales/my-MM.yml @@ -49,6 +49,11 @@ notification: update_found: အကြောင်းအရာဗားရှင်းအသစ်ကို ရနိုင်ပါပြီ။ update: အပ်ဒိတ် +theme: + light: အလင်း + dark: အမှောင် + system: စနစ် + # ----- Posts related labels ----- post: diff --git a/_data/locales/nl-NL.yml b/_data/locales/nl-NL.yml index 691fb75c7..e39281b49 100644 --- a/_data/locales/nl-NL.yml +++ b/_data/locales/nl-NL.yml @@ -49,6 +49,11 @@ notification: update_found: Nieuwe versie van inhoud beschikbaar. update: Update +theme: + light: Licht + dark: Donker + system: Systeem + # ----- Posts related labels ----- post: written_by: Door diff --git a/_data/locales/ps‑AF.yml b/_data/locales/ps‑AF.yml index fa2c19246..0ea9ac23f 100644 --- a/_data/locales/ps‑AF.yml +++ b/_data/locales/ps‑AF.yml @@ -49,6 +49,11 @@ notification: update_found: نوې نسخه شتون لري. update: تازه +theme: + light: روښانه + dark: تیاره + system: سیستم + # ----- Posts related labels ----- post: diff --git a/_data/locales/pt-BR.yml b/_data/locales/pt-BR.yml index 22de99ae6..ec7fb35b9 100644 --- a/_data/locales/pt-BR.yml +++ b/_data/locales/pt-BR.yml @@ -49,6 +49,11 @@ notification: update_found: Uma nova versão do conteúdo está disponível. update: atualização +theme: + light: Claro + dark: Escuro + system: Sistema + # ----- Posts related labels ----- post: diff --git a/_data/locales/ru-RU.yml b/_data/locales/ru-RU.yml index de9e0165b..8842bb813 100644 --- a/_data/locales/ru-RU.yml +++ b/_data/locales/ru-RU.yml @@ -48,6 +48,11 @@ notification: update_found: Доступна новая версия контента. update: Обновить +theme: + light: Светлая + dark: Темная + system: Системная + # ----- Posts related labels ----- post: diff --git a/_data/locales/sl-SI.yml b/_data/locales/sl-SI.yml index 9b3ea4696..61a932897 100644 --- a/_data/locales/sl-SI.yml +++ b/_data/locales/sl-SI.yml @@ -49,6 +49,11 @@ notification: update_found: Novejša različica vsebine je na voljo. #A new version of content is available. update: Posodobi #Update +theme: + light: Svetla + dark: Temna + system: Sistemska + # ----- Posts related labels ----- post: diff --git a/_data/locales/sv-SE.yml b/_data/locales/sv-SE.yml index 77e6fe6b8..5882a8b4f 100644 --- a/_data/locales/sv-SE.yml +++ b/_data/locales/sv-SE.yml @@ -49,6 +49,11 @@ notification: update_found: Det finns en ny version av innehållet. update: Uppdatera sidan +theme: + light: Ljust + dark: Mörkt + system: System + # ----- Posts related labels ----- post: diff --git a/_data/locales/th.yml b/_data/locales/th.yml index c9560fc86..6b54739ae 100644 --- a/_data/locales/th.yml +++ b/_data/locales/th.yml @@ -49,6 +49,11 @@ notification: update_found: มีเวอร์ชันใหม่ของเนื้อหา update: อัปเดต +theme: + light: สว่าง + dark: มืด + system: ระบบ + # ----- Posts related labels ----- post: diff --git a/_data/locales/tr-TR.yml b/_data/locales/tr-TR.yml index 4a08722e3..bb9ac9946 100644 --- a/_data/locales/tr-TR.yml +++ b/_data/locales/tr-TR.yml @@ -49,6 +49,11 @@ notification: update_found: İçeriğin yeni bir sürümü mevcut. update: Güncelle +theme: + light: Açık + dark: Koyu + system: Sistem + # ----- Posts related labels ----- post: diff --git a/_data/locales/uk-UA.yml b/_data/locales/uk-UA.yml index f337187d6..e2cbbff40 100644 --- a/_data/locales/uk-UA.yml +++ b/_data/locales/uk-UA.yml @@ -49,6 +49,11 @@ notification: update_found: Доступна нова версія вмісту. update: Оновлення +theme: + light: Світла + dark: Темна + system: Системна + # ----- Posts related labels ----- post: diff --git a/_data/locales/ur-PK.yml b/_data/locales/ur-PK.yml index 081bc2086..e25522076 100644 --- a/_data/locales/ur-PK.yml +++ b/_data/locales/ur-PK.yml @@ -49,6 +49,11 @@ notification: update_found: نیا مواد دستیاب ہے۔ update: اپ ڈیٹ +theme: + light: روشن + dark: تاریک + system: سسٹم + # ----- Posts related labels ----- post: diff --git a/_data/locales/vi-VN.yml b/_data/locales/vi-VN.yml index 48b767e8b..b82ec50f1 100644 --- a/_data/locales/vi-VN.yml +++ b/_data/locales/vi-VN.yml @@ -48,6 +48,11 @@ notification: update_found: Đã có phiên bản mới của nội dung. update: Cập nhật +theme: + light: Sáng + dark: Tối + system: Hệ thống + # ----- Posts related labels ----- post: diff --git a/_data/locales/zh-CN.yml b/_data/locales/zh-CN.yml index 9a3b2fb67..8cbfe1fac 100644 --- a/_data/locales/zh-CN.yml +++ b/_data/locales/zh-CN.yml @@ -48,6 +48,11 @@ notification: update_found: 发现新版本的内容。 update: 更新 +theme: + light: 浅色 + dark: 深色 + system: 跟随系统 + # ----- Posts related labels ----- post: diff --git a/_data/locales/zh-TW.yml b/_data/locales/zh-TW.yml index ad4ea6898..7afeb420a 100644 --- a/_data/locales/zh-TW.yml +++ b/_data/locales/zh-TW.yml @@ -48,6 +48,11 @@ notification: update_found: 發現新版本更新。 update: 更新 +theme: + light: 淺色 + dark: 深色 + system: 跟隨系統 + # ----- Posts related labels ----- post: diff --git a/_data/origin/cors.yml b/_data/origin/cors.yml index e40cc357d..719d8fbe4 100644 --- a/_data/origin/cors.yml +++ b/_data/origin/cors.yml @@ -19,6 +19,9 @@ webfonts: https://fonts.googleapis.com/css2?family=Lato:wght@300;400&family=Sour # Libraries +bootstrap: + css: https://cdn.jsdelivr.net/npm/bootstrap@5/dist/css/bootstrap.min.css + toc: css: https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.css js: https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js diff --git a/_includes/comments/disqus.html b/_includes/comments/disqus.html index fd12a3c72..0fb676606 100644 --- a/_includes/comments/disqus.html +++ b/_includes/comments/disqus.html @@ -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); } diff --git a/_includes/comments/giscus.html b/_includes/comments/giscus.html index 2d5f7e7bf..ddaf64706 100644 --- a/_includes/comments/giscus.html +++ b/_includes/comments/giscus.html @@ -1,8 +1,8 @@