forked from solidjs/solid-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry-server.tsx
More file actions
62 lines (57 loc) · 1.81 KB
/
entry-server.tsx
File metadata and controls
62 lines (57 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { createHandler, StartServer } from "@solidjs/start/server";
export default createHandler(() => (
<StartServer
document={({ assets, children, scripts }) => {
return (
<html
lang="en"
>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1"
/>
<link rel="icon" href="/favicon.ico" />
<link
rel="alternate icon"
href="/favicon.svg"
type="image/svg+xml"
/>
<script> {`
function getCookie(name, cookieString) {
if (!name || !cookieString) return "system";
const match = cookieString.match(new RegExp(\`\\\\W?\${name}=(?<theme>\\\\w+)\`));
return match?.groups?.theme || "system";
}
const getUserTheme = () => getCookie("theme", document.cookie);
const getSystemTheme = () => window.matchMedia("(prefers-color-scheme: dark)").matches
? {value: "dark", theme: "material-theme-ocean" }
: {value: "light", theme: "min-light" };
const systemTheme = getSystemTheme();
const themes = [
{ value: "light", theme: "min-light" },
{ value: "dark", theme: "material-theme-ocean" },
{
value: systemTheme.value,
theme: systemTheme.theme,
},
];
const themeName = getUserTheme();
const theme = themes.find((t) => t.value == themeName) ?? themes[2];
document.documentElement.classList.add(theme.value);
document.documentElement.setAttribute('data-theme', theme.theme);
`}
</script>
<script src="/scripts/browser-specific.js" type="module" />
{assets}
</head>
<body class="min-h-screen dark:bg-slate-900 bg-slate-50">
<div id="app">{children}</div>
{scripts}
</body>
</html>
);
}}
/>
));