File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,5 +19,8 @@ export default /** @type {import('astro').AstroUserConfig} */ {
1919 devOptions : {
2020 // port: 3000, // The port to run the dev server on.
2121 tailwindConfig : './tailwind.config.js' , // Path to tailwind.config.js if used, e.g. './tailwind.config.js'
22- }
22+ } ,
23+ renderers : [
24+ '@astrojs/renderer-svelte' ,
25+ ]
2326} ;
Original file line number Diff line number Diff line change 1- <body class =" font-sans antialiased bg-gray-100 dark:bg-gray-800 transition-colors" >
1+ <body class =" font-sans antialiased" >
2+ <div class =" bg-gray-100 dark:bg-gray-800 transition-colors" >
23 <main class =" mx-auto max-w-4xl px-4 md:px-0" >
34 <slot />
45 </main >
6+ </div >
57</body >
Original file line number Diff line number Diff line change 11---
22 import { SITE } from ' $/config'
33 import SvgIcon from ' ./SvgIcon.astro'
4+ import ModeSwitcher from ' ./ModeSwitcher.svelte'
45---
56
67<header class =" header" >
2627 </SvgIcon >
2728 </a >
2829 </li >
30+ <li >
31+ <ModeSwitcher client:visible >
32+ <SvgIcon >
33+ <circle cx =" 12" cy =" 12" r =" 5" ></circle >
34+ <line x1 =" 12" y1 =" 1" x2 =" 12" y2 =" 3" ></line >
35+ <line x1 =" 12" y1 =" 21" x2 =" 12" y2 =" 23" ></line >
36+ <line x1 =" 4.22" y1 =" 4.22" x2 =" 5.64" y2 =" 5.64" ></line >
37+ <line x1 =" 18.36" y1 =" 18.36" x2 =" 19.78" y2 =" 19.78" ></line >
38+ <line x1 =" 1" y1 =" 12" x2 =" 3" y2 =" 12" ></line >
39+ <line x1 =" 21" y1 =" 12" x2 =" 23" y2 =" 12" ></line >
40+ <line x1 =" 4.22" y1 =" 19.78" x2 =" 5.64" y2 =" 18.36" ></line >
41+ <line x1 =" 18.36" y1 =" 5.64" x2 =" 19.78" y2 =" 4.22" ></line >
42+ </SvgIcon >
43+ </ModeSwitcher >
44+ </li >
2945 </ul >
3046 </nav >
3147 </div >
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import { onMount } from ' svelte'
3+
4+ type ThemeType = ' dark' | ' light'
5+
6+ const THEME_DARK: ThemeType = ' dark'
7+ const THEME_LIGHT: ThemeType = ' light'
8+ let currTheme: ThemeType = THEME_DARK
9+
10+
11+ function toggleTheme() {
12+ window .document .body .classList .toggle (THEME_DARK )
13+ currTheme = localStorage .getItem (' theme' ) === THEME_DARK ? THEME_LIGHT : THEME_DARK
14+ localStorage .setItem (' theme' , currTheme )
15+ }
16+
17+ onMount (() => {
18+ if (localStorage .getItem (' theme' ) === THEME_DARK || (! (' theme' in localStorage ) && window .matchMedia (` (prefers-color-scheme: ${THEME_DARK }) ` ).matches )) {
19+ window .document .body .classList .add (THEME_DARK )
20+ currTheme = THEME_DARK
21+ } else {
22+ window .document .body .classList .remove (THEME_DARK )
23+ currTheme = THEME_LIGHT
24+ }
25+ })
26+ </script >
27+ <button on:click ={toggleTheme }>
28+ <slot theme ={currTheme }/>
29+ </button >
You can’t perform that action at this time.
0 commit comments