-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Dark mode optimization. - Auto dark mode based on system preference. - Manual toggle switch at the bottom of the page. - Instant and dynamic responding. * default.html. Optimization on dark mode button. * improve dark theme toggle in default.html in advance * Fix inconsistency of font family. * Fix accidentally deleting archive navigator in footer. * Rewrite CSS based on variables. * Attempt to fix the logic of switching dark and light theme. (For most cases it works.) * Add auto theme option to theme switch. - Toggle option: dark, light, auto. - Reformat some files. - Fix the logic conflict of theme switch. * Fix the italic style of <i> in button.
- Loading branch information
Showing
12 changed files
with
926 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
_posts/ | ||
_site/ | ||
.*/ | ||
/vendor | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
document.addEventListener('DOMContentLoaded', () => { | ||
'use strict'; | ||
|
||
const root = document.querySelector(':root'); | ||
const schemeMedia = window.matchMedia('(prefers-color-scheme: dark)'); | ||
const themeBtn = document.querySelector('button.scheme'); | ||
const themeIcon = themeBtn.querySelector('i'); | ||
|
||
themeBtn.classList.remove('hidden'); | ||
|
||
function setThemeUIState() { | ||
const themeState = localStorage.getItem('theme') || 'auto'; | ||
const icon = { | ||
light: 'sun', | ||
dark: 'moon', | ||
}[themeState] || 'adjust'; | ||
|
||
themeIcon.className = `toggle d-${icon}`; | ||
|
||
if (themeState === 'auto') { | ||
delete root.dataset.scheme; | ||
} else { | ||
root.dataset.scheme = themeState; | ||
} | ||
} | ||
|
||
function setThemeExplicitly() { | ||
const themeOrder = schemeMedia.matches | ||
? ['auto', 'light', 'dark'] | ||
: ['auto', 'dark', 'light']; | ||
|
||
const storedTheme = localStorage.getItem('theme'); | ||
const themeState = themeOrder.includes(storedTheme) ? storedTheme : 'auto'; | ||
const nextState = (() => { | ||
let current; | ||
do { | ||
current = themeOrder.shift(); | ||
themeOrder.push(current); | ||
} while (current !== themeState); | ||
return themeOrder.shift(); | ||
})(); | ||
|
||
localStorage.setItem('theme', nextState); | ||
setThemeUIState(); | ||
} | ||
|
||
schemeMedia.addEventListener('change', () => { | ||
document.body.className = 'transitions'; | ||
setThemeUIState(); | ||
}); | ||
setThemeUIState(); | ||
|
||
themeBtn.addEventListener('click', () => { | ||
document.body.className = 'transitions'; | ||
setThemeExplicitly(); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* light color set | ||
--post-tc1: #222222; | ||
--post-tc2: #888888; | ||
--post-tc3: #444444; | ||
--news-tc1: #222222; | ||
--news-tc2: #222222; | ||
--news-bd: #222222; | ||
--bkg-color: #ffffff; | ||
--page-num: #222222; | ||
--page-next: #444444; | ||
*/ | ||
|
||
|
||
/* dark color set | ||
--post-tc1: #e6e8ea; | ||
--post-tc2: #a0a7ae; | ||
--post-tc3: #e1dfdc; | ||
--news-tc1: #e6e8ea; | ||
--news-tc2: #e1dfdc; | ||
--news-bd: #c8cccf; | ||
--bkg-color: #1e2023; | ||
--page-num: #adb3b9; | ||
--page-next: #e1dfdc; | ||
*/ | ||
|
||
:root { | ||
--post-tc1: #222222; | ||
--post-tc2: #888888; | ||
--post-tc3: #444444; | ||
|
||
--news-tc1: #222222; | ||
--news-tc2: #222222; | ||
--news-bd: #222222; | ||
|
||
--bkg-color: #ffffff; | ||
--page-num: #222222; | ||
--page-next: #444444; | ||
} | ||
|
||
:root[data-scheme="dark"] { | ||
--post-tc1: #e6e8ea; /* h1, h2, h3 */ | ||
--post-tc2: #a0a7ae; /* h4 */ | ||
--post-tc3: #e1dfdc; /* p */ | ||
|
||
--news-tc1: #e6e8ea; /* h1, h2, h3 | h4 h5 h6 */ | ||
--news-tc2: #e1dfdc; /* p, blockquote, ul, ol, li */ | ||
--news-bd: #c8cccf; /* item border */ | ||
|
||
--bkg-color: #1e2023; /* universal */ | ||
--page-num: #adb3b9; | ||
--page-next: #e1dfdc; | ||
} | ||
|
||
@media (prefers-color-scheme: dark) { | ||
:root:not([data-scheme="light"]) { | ||
--post-tc1: #e6e8ea; /* h1, h2, h3 */ | ||
--post-tc2: #a0a7ae; /* h4 */ | ||
--post-tc3: #e1dfdc; /* p */ | ||
|
||
--news-tc1: #e6e8ea; /* h1, h2, h3 | h4 h5 h6 */ | ||
--news-tc2: #e1dfdc; /* p, blockquote, ul, ol, li */ | ||
--news-bd: #c8cccf; /* item border */ | ||
|
||
--bkg-color: #1e2023; /* universal */ | ||
--page-num: #adb3b9; | ||
--page-next: #e1dfdc; | ||
} | ||
} | ||
|
||
|
||
/* */ | ||
|
||
.hidden { | ||
display:none | ||
} | ||
|
||
button.scheme { | ||
background: none; | ||
border: none; | ||
margin: 0; | ||
outline: none; | ||
padding:none | ||
} | ||
|
||
button.scheme:hover { | ||
cursor:pointer | ||
} | ||
|
||
.toggle{ | ||
font-size: 1em; | ||
font-style: normal; | ||
} | ||
|
||
.d-sun:after{ | ||
content: "🌕"; | ||
} | ||
|
||
.d-moon:after{ | ||
content: "🌑"; | ||
} | ||
|
||
.d-adjust:after{ | ||
content: "🌓"; | ||
} | ||
|
||
/* | ||
body.light-theme { | ||
--post-tc1: #222222; | ||
--post-tc2: #888888; | ||
--post-tc3: #444444; | ||
--news-tc1: #222222; | ||
--news-tc2: #222222; | ||
--news-bd: #222222; | ||
--bkg-color: #ffffff; | ||
--page-num: #222222; | ||
--page-next: #444444; | ||
}*/ | ||
|
||
|
||
/* | ||
--bkg-color is universal. | ||
Default color settings: | ||
post.css: | ||
- post-tc1(h1, h2, h3): #222222 | ||
- post-tc2(h4): #888888 | ||
- post-tc3(p): #444444 | ||
newspaper.css: | ||
**Colors are not specified originally.** | ||
- news-tc1(h1, h2, h3): #222222 | ||
- news-tc2(p, blockquote): #222222 | ||
- news-bd(item border): #222222 | ||
*/ | ||
|
||
/*h1, p, h2, h3, h4, h5, h6, a, blockquote, ul, ol, li { | ||
color: var(--text-color); | ||
}*/ | ||
|
||
a.next, div.pagination{ | ||
color: var(--page-next); | ||
} | ||
|
||
span.page_number{ | ||
color: var(--page-num); | ||
} | ||
|
||
|
||
.btn-toggle{ | ||
cursor: pointer; | ||
-webkit-user-select:none; | ||
-moz-user-select:none; | ||
-ms-user-select:none; | ||
user-select:none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.