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:
@@ -1,3 +1,9 @@
|
||||
@mixin color-scheme($mode) {
|
||||
@media (prefers-color-scheme: #{$mode}) {
|
||||
@content;
|
||||
}
|
||||
}
|
||||
|
||||
@mixin text-ellipsis {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
@@ -28,3 +28,9 @@ $code-icon-width: 1.75rem !default;
|
||||
|
||||
$font-family-base: 'Source Sans Pro', 'Microsoft Yahei', sans-serif !default;
|
||||
$font-family-heading: Lato, 'Microsoft Yahei', sans-serif !default;
|
||||
|
||||
/* Theme mode settings */
|
||||
|
||||
$theme-attr: 'data-bs-theme'; /* the attribute used to indicate the resolved theme */
|
||||
$theme-options: light, dark;
|
||||
$theme: null !default; /* set by Jekyll site configuration */
|
||||
|
||||
+25
-18
@@ -1,3 +1,4 @@
|
||||
@use 'sass:list';
|
||||
@use '../abstracts/variables' as v;
|
||||
@use '../abstracts/breakpoints' as bp;
|
||||
@use '../abstracts/mixins' as mx;
|
||||
@@ -5,32 +6,36 @@
|
||||
@use '../themes/light';
|
||||
@use '../themes/dark';
|
||||
|
||||
:root {
|
||||
font-size: 16px;
|
||||
$enable-dual: not list.index(v.$theme-options, v.$theme);
|
||||
$enable-light: v.$theme == light or $enable-dual;
|
||||
$enable-dark: v.$theme == dark or $enable-dual;
|
||||
|
||||
@if $enable-light {
|
||||
:root[#{v.$theme-attr}='light'] {
|
||||
@include light.styles;
|
||||
}
|
||||
}
|
||||
|
||||
html {
|
||||
@media (prefers-color-scheme: light) {
|
||||
&:not([data-mode]),
|
||||
&[data-mode='light'] {
|
||||
@if $enable-dark {
|
||||
:root[#{v.$theme-attr}='dark'] {
|
||||
@include dark.styles;
|
||||
}
|
||||
}
|
||||
|
||||
@if $enable-dual {
|
||||
:root:not([#{v.$theme-attr}]) {
|
||||
@include mx.color-scheme(light) {
|
||||
@include light.styles;
|
||||
}
|
||||
|
||||
&[data-mode='dark'] {
|
||||
@include mx.color-scheme(dark) {
|
||||
@include dark.styles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
&:not([data-mode]),
|
||||
&[data-mode='dark'] {
|
||||
@include dark.styles;
|
||||
}
|
||||
|
||||
&[data-mode='light'] {
|
||||
@include light.styles;
|
||||
}
|
||||
}
|
||||
:root {
|
||||
font-size: 16px;
|
||||
|
||||
@include bp.lg {
|
||||
overflow-y: scroll;
|
||||
@@ -369,7 +374,9 @@ main {
|
||||
box-shadow: none;
|
||||
border-color: var(--input-focus-border-color) !important;
|
||||
background: center !important;
|
||||
transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
|
||||
transition:
|
||||
background-color 0.15s ease-in-out,
|
||||
border-color 0.15s ease-in-out;
|
||||
}
|
||||
|
||||
.left {
|
||||
|
||||
@@ -17,7 +17,6 @@ $sidebar-display: 'sidebar-display'; /* the attribute for sidebar display */
|
||||
overflow-y: auto;
|
||||
width: v.$sidebar-width;
|
||||
background: var(--sidebar-bg);
|
||||
border-right: 1px solid var(--sidebar-border-color);
|
||||
|
||||
/* Hide scrollbar for IE, Edge and Firefox */
|
||||
-ms-overflow-style: none; /* IE and Edge */
|
||||
@@ -105,6 +104,8 @@ $sidebar-display: 'sidebar-display'; /* the attribute for sidebar display */
|
||||
letter-spacing: 0.25px;
|
||||
margin-top: 1.25rem;
|
||||
margin-bottom: 0.5rem;
|
||||
width: -webkit-fit-content;
|
||||
width: -moz-fit-content;
|
||||
width: fit-content;
|
||||
color: var(--site-title-color);
|
||||
}
|
||||
@@ -207,7 +208,7 @@ $sidebar-display: 'sidebar-display'; /* the attribute for sidebar display */
|
||||
}
|
||||
}
|
||||
|
||||
a {
|
||||
> a {
|
||||
@extend %button;
|
||||
@extend %sidebar-link-hover;
|
||||
@extend %clickable-transition;
|
||||
@@ -227,13 +228,102 @@ $sidebar-display: 'sidebar-display'; /* the attribute for sidebar display */
|
||||
|
||||
#mode-toggle {
|
||||
@extend %button;
|
||||
@extend %sidebar-links;
|
||||
@extend %sidebar-link-hover;
|
||||
@extend %clickable-transition;
|
||||
|
||||
> i {
|
||||
display: none;
|
||||
|
||||
@at-root :root[data-bs-theme='light'][data-theme-persisted]
|
||||
&[data-theme-mode='light'] {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@at-root :root[data-bs-theme='dark'][data-theme-persisted]
|
||||
&[data-theme-mode='dark'] {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@at-root :root:not([data-theme-persisted]) &[data-theme-mode='system'] {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
@-webkit-keyframes menu-pop {
|
||||
from {
|
||||
opacity: 0;
|
||||
translate: 0 0.5rem;
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
translate: 0 0;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes menu-pop {
|
||||
from {
|
||||
opacity: 0;
|
||||
translate: 0 0.5rem;
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
translate: 0 0;
|
||||
}
|
||||
}
|
||||
|
||||
+ .dropdown-menu {
|
||||
background-color: var(--menu-bg);
|
||||
border-color: var(--menu-border-color);
|
||||
box-shadow: var(--menu-shadow-color) 0 1px 4px;
|
||||
border-radius: 0.75rem !important;
|
||||
|
||||
&.show {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
left: -0.25rem !important;
|
||||
-webkit-animation: menu-pop 0.2s ease-out;
|
||||
animation: menu-pop 0.2s ease-out;
|
||||
}
|
||||
|
||||
.dropdown-item {
|
||||
border-radius: 0.5rem;
|
||||
color: var(--sidebar-muted-color);
|
||||
font-size: 90%;
|
||||
|
||||
&.active {
|
||||
font-weight: 600;
|
||||
color: var(--menu-active-color);
|
||||
|
||||
&::after {
|
||||
content: '\f00c';
|
||||
font: var(--fa-font-solid);
|
||||
font-size: 0.75rem;
|
||||
color: var(--sidebar-btn-color);
|
||||
margin-left: auto;
|
||||
padding-left: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
&:active,
|
||||
&:hover,
|
||||
&.active {
|
||||
background-color: var(--menu-highlight-bg);
|
||||
}
|
||||
|
||||
> i {
|
||||
color: var(--sidebar-btn-color);
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.icon-border {
|
||||
@extend %no-cursor;
|
||||
@include mx.ml-mr(calc((v.$sb-btn-gap - $btn-border-width) / 2));
|
||||
@include mx.ml-mr(0.6rem);
|
||||
|
||||
background-color: var(--sidebar-btn-color);
|
||||
content: '';
|
||||
@@ -241,10 +331,6 @@ $sidebar-display: 'sidebar-display'; /* the attribute for sidebar display */
|
||||
height: $btn-border-width;
|
||||
border-radius: 50%;
|
||||
margin-bottom: $btn-mb;
|
||||
|
||||
@include bp.xxxl {
|
||||
@include mx.ml-mr(calc((v.$sb-btn-gap-lg - $btn-border-width) / 2));
|
||||
}
|
||||
}
|
||||
} /* .sidebar-bottom */
|
||||
} /* #sidebar */
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
rgb(58 55 55 / 40%) 50%,
|
||||
rgb(255 255 255 / 0%) 100%
|
||||
);
|
||||
--menu-bg: rgb(30 30 30);
|
||||
--menu-border-color: rgb(77 77 77 / 60%);
|
||||
--menu-shadow-color: rgb(4 4 4 / 42%);
|
||||
--menu-active-color: rgb(240 248 255 / 63%);
|
||||
--menu-highlight-bg: rgb(90 91 92 / 12%);
|
||||
|
||||
/* Sidebar */
|
||||
--site-title-color: #717070;
|
||||
@@ -67,8 +72,8 @@
|
||||
--btn-share-hover-color: #bfc1ca;
|
||||
--card-bg: #1e1e1e;
|
||||
--card-hover-bg: #464d51;
|
||||
--card-shadow: rgb(21 21 21 / 72%) 0 6px 18px 0,
|
||||
rgb(137 135 135 / 24%) 0 0 0 1px;
|
||||
--card-shadow:
|
||||
rgb(21 21 21 / 72%) 0 6px 18px 0, rgb(137 135 135 / 24%) 0 0 0 1px;
|
||||
--kbd-wrap-color: #6a6a6a;
|
||||
--kbd-text-color: #d3d3d3;
|
||||
--kbd-bg-color: #242424;
|
||||
|
||||
@@ -27,6 +27,11 @@
|
||||
rgb(232 230 230 / 100%) 50%,
|
||||
rgb(250 250 250 / 0%) 100%
|
||||
);
|
||||
--menu-bg: white;
|
||||
--menu-border-color: white;
|
||||
--menu-shadow-color: rgb(0 0 0 / 16%);
|
||||
--menu-active-color: rgb(91 91 91);
|
||||
--menu-highlight-bg: rgb(243 244 245 / 50%);
|
||||
|
||||
/* Sidebar */
|
||||
--site-title-color: rgb(113 113 113);
|
||||
@@ -59,8 +64,8 @@
|
||||
--btn-share-hover-color: #0d6efd;
|
||||
--card-bg: white;
|
||||
--card-hover-bg: #e2e2e2;
|
||||
--card-shadow: rgb(104 104 104 / 5%) 0 2px 6px 0,
|
||||
rgb(211 209 209 / 15%) 0 0 0 1px;
|
||||
--card-shadow:
|
||||
rgb(104 104 104 / 5%) 0 2px 6px 0, rgb(211 209 209 / 15%) 0 0 0 1px;
|
||||
--footnote-target-bg: lightcyan;
|
||||
--tb-odd-bg: #fbfcfd;
|
||||
--tb-border-color: #eaeaea;
|
||||
|
||||
Reference in New Issue
Block a user