critique 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/ansi-html.ts +11 -0
- package/src/worker.ts +17 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# 0.1.12
|
|
2
|
+
|
|
3
|
+
- Web preview:
|
|
4
|
+
- Add client-side mobile detection with redirect to `?v=mobile`
|
|
5
|
+
- Simplify worker: redirect mobile devices instead of content negotiation
|
|
6
|
+
- Remove `Vary` header - URL now determines content, better caching
|
|
7
|
+
- Increase cache max-age to 24h (was 1h)
|
|
8
|
+
|
|
1
9
|
# 0.1.11
|
|
2
10
|
|
|
3
11
|
- All commands:
|
package/package.json
CHANGED
package/src/ansi-html.ts
CHANGED
|
@@ -204,6 +204,17 @@ ${content}
|
|
|
204
204
|
const minFontSize = 4;
|
|
205
205
|
const maxFontSize = 16;
|
|
206
206
|
|
|
207
|
+
// Redirect mobile devices to ?v=mobile for optimized view
|
|
208
|
+
// Only redirect if not already on a forced version
|
|
209
|
+
const params = new URLSearchParams(window.location.search);
|
|
210
|
+
if (!params.has('v')) {
|
|
211
|
+
const isMobile = /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|Opera M(obi|ini)|Windows Phone|webOS/i.test(navigator.userAgent);
|
|
212
|
+
if (isMobile) {
|
|
213
|
+
params.set('v', 'mobile');
|
|
214
|
+
window.location.replace(window.location.pathname + '?' + params.toString());
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
207
218
|
function adjustFontSize() {
|
|
208
219
|
const viewportWidth = window.innerWidth;
|
|
209
220
|
const calculatedSize = (viewportWidth - padding) / (cols * charRatio);
|
package/src/worker.ts
CHANGED
|
@@ -90,7 +90,8 @@ app.post("/upload", async (c) => {
|
|
|
90
90
|
|
|
91
91
|
// View HTML content with streaming
|
|
92
92
|
// GET /view/:id
|
|
93
|
-
// Query params: ?v=desktop or ?v=mobile to
|
|
93
|
+
// Query params: ?v=desktop or ?v=mobile to select version
|
|
94
|
+
// Server redirects mobile devices to ?v=mobile, client JS also handles redirect
|
|
94
95
|
app.get("/view/:id", async (c) => {
|
|
95
96
|
const id = c.req.param("id")
|
|
96
97
|
|
|
@@ -98,12 +99,21 @@ app.get("/view/:id", async (c) => {
|
|
|
98
99
|
return c.text("Invalid ID", 400)
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
// Check for
|
|
102
|
-
const
|
|
103
|
-
|
|
102
|
+
// Check for version query param
|
|
103
|
+
const version = c.req.query("v")
|
|
104
|
+
|
|
105
|
+
// If no version specified and mobile device detected, redirect to ?v=mobile
|
|
106
|
+
// This is a fallback - client JS also handles this redirect
|
|
107
|
+
if (!version && isMobileDevice(c)) {
|
|
108
|
+
const url = new URL(c.req.url)
|
|
109
|
+
url.searchParams.set("v", "mobile")
|
|
110
|
+
return c.redirect(url.toString(), 302)
|
|
111
|
+
}
|
|
104
112
|
|
|
105
|
-
//
|
|
113
|
+
// Serve the appropriate version based on query param
|
|
114
|
+
const isMobile = version === "mobile"
|
|
106
115
|
let html: string | null = null
|
|
116
|
+
|
|
107
117
|
if (isMobile) {
|
|
108
118
|
// Try mobile version first, fall back to desktop
|
|
109
119
|
html = await c.env.CRITIQUE_KV.get(`${id}-mobile`)
|
|
@@ -120,11 +130,9 @@ app.get("/view/:id", async (c) => {
|
|
|
120
130
|
|
|
121
131
|
// Stream the HTML content for faster initial load
|
|
122
132
|
return stream(c, async (s) => {
|
|
123
|
-
// Set content type header
|
|
124
133
|
c.header("Content-Type", "text/html; charset=utf-8")
|
|
125
|
-
//
|
|
126
|
-
c.header("
|
|
127
|
-
c.header("Cache-Control", "public, max-age=3600")
|
|
134
|
+
// Cache is now safe - URL determines content, no Vary needed
|
|
135
|
+
c.header("Cache-Control", "public, max-age=86400")
|
|
128
136
|
|
|
129
137
|
// Stream in chunks for better performance
|
|
130
138
|
const chunkSize = 16 * 1024 // 16KB chunks
|