Skip to content

Commit

Permalink
Fix theme preference bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JuditKaramazov committed Jan 10, 2024
1 parent 70a98d1 commit c6f2f7a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/layouts/Base/Head.astro
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const appleTouchIcon = await getImage({

<head>
<script is:inline>
const theme = localStorage.getItem('@karamablog/theme') || 'light'
const preferredTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
const theme = localStorage.getItem('@karamablog/theme') || preferredTheme
document.documentElement.dataset.theme = theme
</script>
<meta charset="utf-8" />
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/Base/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const { pageTitle } = Astro.props

<html lang="en">
<script is:inline>
const theme = localStorage.getItem('@karamablog/theme') || 'light'
const preferredTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
const theme = localStorage.getItem('@karamablog/theme') || preferredTheme
document.documentElement.dataset.theme = theme
</script>
<Head {...Astro.props} />
Expand Down

0 comments on commit c6f2f7a

Please sign in to comment.