Skip to content

Commit

Permalink
fix: save choosen color scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Mineev authored and umputun committed Aug 22, 2022
1 parent b47b6c4 commit d6b2960
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion site/src/includes/inline.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const mq = window.matchMedia('(prefers-color-scheme: dark)')
const theme = localStorage.getItem('theme')

if (mq.matches) {
if ((theme && theme === 'dark') || (!theme && mq.matches)) {
document.documentElement.classList.add('dark')
}
6 changes: 3 additions & 3 deletions site/src/includes/script.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function toggleTheme() {
const root = document.documentElement
const theme = root.classList.contains('dark') ? 'light' : 'dark'

root.classList.toggle('dark')
localStorage.setItem('theme', theme)

if (window.REMARK42) {
const isDark = root.classList.contains('dark')

window.REMARK42.changeTheme(isDark ? 'dark' : 'light')
window.REMARK42.changeTheme(theme)
}
}
2 changes: 1 addition & 1 deletion site/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@apply before:hidden after:hidden text-brand-800 dark:text-brand-300 font-light;
}
.prose strong code {
@apply font-bold text-yellow-600 dark:text-yellow-400;;
@apply font-bold text-yellow-600 dark:text-yellow-400;
}

.burger-icon {
Expand Down

0 comments on commit d6b2960

Please sign in to comment.