File tree Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -36,12 +36,12 @@ function Links() {
36
36
}
37
37
38
38
export const ThemeToggleBtn = ( props ) => {
39
- const [ theme , setTheme ] = createSignal ( "light " ) ;
39
+ const [ theme , setTheme ] = createSignal ( "" ) ;
40
40
41
41
onMount ( ( ) => {
42
- const localTheme = localStorage . theme
43
- setTheme ( localTheme )
44
- } )
42
+ const localTheme = localStorage . theme ;
43
+ setTheme ( localTheme ) ;
44
+ } ) ;
45
45
46
46
return (
47
47
< button
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ export default createHandler(() => (
6
6
< html lang = "en" >
7
7
< head >
8
8
< meta charset = "utf-8" />
9
- < meta name = "viewport" content = "width=device-width, initial-scale=1" />
9
+ < meta name = "viewport" content = "width=device-width, initial-scale=1" />
10
10
11
11
{ /* favicon & font */ }
12
12
< link rel = "icon" type = "image/svg+xml" href = "/logo.svg" />
@@ -24,9 +24,11 @@ export default createHandler(() => (
24
24
25
25
{ assets }
26
26
27
- { /* set saved theme */ }
27
+ { /* Check if a theme is saved in localStorage, if not, set it based on the system's theme preference */ }
28
28
< script >
29
- document.querySelector("html").className = localStorage.theme
29
+ if (!localStorage.theme)
30
+ localStorage.theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
31
+ document.querySelector("html").className = localStorage.theme;
30
32
</ script >
31
33
</ head >
32
34
< body >
You can’t perform that action at this time.
0 commit comments