1
0
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:
Cotes Chung
2026-06-17 23:20:12 +08:00
committed by GitHub
parent ceb2a41463
commit 7496dd41fa
51 changed files with 541 additions and 153 deletions
+47 -5
View File
@@ -40,11 +40,53 @@
</ul>
</nav>
<div class="sidebar-bottom d-flex flex-wrap align-items-center w-100">
{% unless site.theme_mode %}
<button type="button" class="btn btn-link nav-link" aria-label="Switch Mode" id="mode-toggle">
<i class="fas fa-adjust"></i>
</button>
<div class="sidebar-bottom d-flex flex-wrap align-items-center w-100">
{% unless site.theme_mode == 'light' or site.theme_mode == 'dark' %}
{%- capture icon_system -%}
<i class="fa-solid fa-display" data-theme-mode="system"></i>
{%- endcapture -%}
{%- capture icon_light -%}
<i class="fa-regular fa-sun" data-theme-mode="light"></i>
{%- endcapture -%}
{%- capture icon_dark -%}
<i class="fa-regular fa-moon" data-theme-mode="dark"></i>
{%- endcapture -%}
<div class="btn-group dropup">
<button
type="button"
class="btn btn-link nav-link"
aria-label="Switch Mode"
id="mode-toggle"
data-bs-toggle="dropdown"
>
{{- icon_light -}}
{{- icon_dark -}}
{{- icon_system -}}
</button>
<ul class="dropdown-menu rounded-3 mb-1 p-1">
<li>
<button class="dropdown-item d-flex align-items-center" type="button" data-theme-mode="light">
{{- icon_light -}}
{{- site.data.locales[lang].theme.light -}}
</button>
</li>
<li>
<button class="dropdown-item d-flex align-items-center" type="button" data-theme-mode="dark">
{{- icon_dark -}}
{{- site.data.locales[lang].theme.dark -}}
</button>
</li>
<li>
<button class="dropdown-item d-flex align-items-center" type="button" data-theme-mode="system">
{{- icon_system -}}
{{- site.data.locales[lang].theme.system -}}
</button>
</li>
</ul>
</div>
{% if site.data.contact.size > 0 %}
<span class="icon-border"></span>