@@ -4,6 +4,7 @@ import localFont from "next/font/local";
4
4
import { SearchProvider } from "@/components/search" ;
5
5
import { ThemeProvider } from "@/components/theme-toggle" ;
6
6
import Fathom from "@/components/fathom" ;
7
+ import Script from "next/script" ;
7
8
8
9
const inter = localFont ( {
9
10
src : [
@@ -73,7 +74,55 @@ const ubuntuMono = localFont({
73
74
] ,
74
75
variable : "--font-ubuntu-mono" ,
75
76
} ) ;
77
+
76
78
const js = String . raw ;
79
+ let darkModeScript = js `
80
+ try {
81
+ _updateTheme(localStorage.currentTheme)
82
+ } catch (_) {}
83
+
84
+ try {
85
+ if (/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)) {
86
+ document.documentElement.classList.add('os-macos')
87
+ }
88
+ } catch (_) {}
89
+
90
+ function _updateTheme(theme) {
91
+ let classList = document.documentElement.classList;
92
+
93
+ classList.remove("light", "dark", "system");
94
+ document.querySelectorAll('meta[name="theme-color"]').forEach(el => el.remove())
95
+ if (theme === 'dark') {
96
+ classList.add('dark')
97
+
98
+ let meta = document.createElement('meta')
99
+ meta.name = 'theme-color'
100
+ meta.content = 'oklch(.13 .028 261.692)'
101
+ document.head.appendChild(meta)
102
+ } else if (theme === 'light') {
103
+ classList.add('light')
104
+
105
+ let meta = document.createElement('meta')
106
+ meta.name = 'theme-color'
107
+ meta.content = 'white'
108
+ document.head.appendChild(meta)
109
+ } else {
110
+ classList.add('system')
111
+
112
+ let meta1 = document.createElement('meta')
113
+ meta1.name = 'theme-color'
114
+ meta1.content = 'oklch(.13 .028 261.692)'
115
+ meta1.media = '(prefers-color-scheme: dark)'
116
+ document.head.appendChild(meta1)
117
+
118
+ let meta2 = document.createElement('meta')
119
+ meta2.name = 'theme-color'
120
+ meta2.content = 'white'
121
+ meta2.media = '(prefers-color-scheme: light)'
122
+ document.head.appendChild(meta2)
123
+ }
124
+ }
125
+ ` ;
77
126
78
127
export const metadata : Metadata = {
79
128
metadataBase : new URL ( "https://tailwindcss.com" ) ,
@@ -111,57 +160,7 @@ export default async function RootLayout({
111
160
< meta name = "msapplication-TileColor" content = "#38bdf8" />
112
161
< meta name = "msapplication-config" content = { v ( "/favicons/browserconfig.xml" ) } />
113
162
114
- < script
115
- dangerouslySetInnerHTML = { {
116
- __html : js `
117
- try {
118
- _updateTheme(localStorage.currentTheme)
119
- } catch (_) {}
120
-
121
- try {
122
- if (/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)) {
123
- document.documentElement.classList.add('os-macos')
124
- }
125
- } catch (_) {}
126
-
127
- function _updateTheme(theme) {
128
- let classList = document.documentElement.classList;
129
-
130
- classList.remove("light", "dark", "system");
131
- document.querySelectorAll('meta[name="theme-color"]').forEach(el => el.remove())
132
- if (theme === 'dark') {
133
- classList.add('dark')
134
-
135
- let meta = document.createElement('meta')
136
- meta.name = 'theme-color'
137
- meta.content = 'oklch(.13 .028 261.692)'
138
- document.head.appendChild(meta)
139
- } else if (theme === 'light') {
140
- classList.add('light')
141
-
142
- let meta = document.createElement('meta')
143
- meta.name = 'theme-color'
144
- meta.content = 'white'
145
- document.head.appendChild(meta)
146
- } else {
147
- classList.add('system')
148
-
149
- let meta1 = document.createElement('meta')
150
- meta1.name = 'theme-color'
151
- meta1.content = 'oklch(.13 .028 261.692)'
152
- meta1.media = '(prefers-color-scheme: dark)'
153
- document.head.appendChild(meta1)
154
-
155
- let meta2 = document.createElement('meta')
156
- meta2.name = 'theme-color'
157
- meta2.content = 'white'
158
- meta2.media = '(prefers-color-scheme: light)'
159
- document.head.appendChild(meta2)
160
- }
161
- }
162
- ` ,
163
- } }
164
- />
163
+ < Script src = { `data:text/javascript;base64,${ btoa ( darkModeScript ) } ` } />
165
164
</ head >
166
165
< body >
167
166
< Fathom />
0 commit comments