-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.tsx
More file actions
124 lines (107 loc) · 3.48 KB
/
main.tsx
File metadata and controls
124 lines (107 loc) · 3.48 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/** @jsx h */
/** @jsxFrag Fragment */
import { App, staticFiles } from "fresh";
import { Fragment, h } from "preact";
import { type State } from "./utils.ts";
import { defaultSiteConfig } from "./utils/meta.ts";
import "jsr:@std/dotenv@0.225.5/load";
export const app = new App<State>();
app.appWrapper(({ Component }) => {
return (
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{defaultSiteConfig.name}</title>
<meta name="description" content={defaultSiteConfig.description} />
<link rel="stylesheet" href="/styles.css" />
<link rel="icon" href="/logo.svg" />
<link rel="manifest" href="/manifest.json" />
<meta name="theme-color" content="#89b4fa" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="mobile-web-app-status-bar-style" content="default" />
<meta name="mobile-web-app-title" content="Andromeda" />
<link rel="apple-touch-icon" href="/logo.svg" />
<script src="/pwa-cache.js" defer></script>
<link
rel="alternate"
type="application/rss+xml"
title="Andromeda Blog RSS Feed"
href="/blog/rss.xml"
/>
<link
rel="alternate"
type="application/atom+xml"
title="Andromeda Blog Atom Feed"
href="/blog/atom.xml"
/>
<link
rel="alternate"
type="application/feed+json"
title="Andromeda Blog JSON Feed"
href="/blog/feed.json"
/>
<script
dangerouslySetInnerHTML={{
__html: `function updateTheme() {
document.documentElement.classList.toggle("dark",
localStorage.theme === "dark" ||
(!("theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches)
);
}
// Initial theme setup
updateTheme();
// Listen for system theme changes
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", updateTheme);
// Listen for storage changes (in case theme is changed in another tab)
window.addEventListener("storage", function(e) {
if (e.key === "theme") {
updateTheme();
}
});
// Service Worker Registration for PWA
if ("serviceWorker" in navigator) {
window.addEventListener("load", function() {
navigator.serviceWorker.register("/sw.js")
.then(function(registration) {
console.log("SW registration successful with scope: ", registration.scope);
// Handle updates
registration.addEventListener("updatefound", function() {
const newWorker = registration.installing;
if (newWorker) {
newWorker.addEventListener("statechange", function() {
if (newWorker.state === "installed" && navigator.serviceWorker.controller) {
// New content is available, show update notification
console.log("New content available, please refresh.");
}
});
}
});
})
.catch(function(error) {
console.log("SW registration failed: ", error);
});
});
}`,
}}
/>
</head>
<body class="min-h-screen bg-base text-text">
<Component />
</body>
</html>
);
});
app.use(staticFiles());
app.fsRoutes();
app.get("/docs", () => {
return new Response(null, {
status: 302,
headers: {
Location: "/docs/index",
},
});
});
if (import.meta.main) {
await app.listen();
}