Skip to content

Commit cfe3a24

Browse files
author
Miriad
committed
debug: systematic isolation — 5 levels of HTML complexity via ?level=1-5
1 parent 993af5b commit cfe3a24

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed
Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Default OG image — debug: dump HTML to inspect what Satori receives.
3-
* Also test rendering with the minimal approach for comparison.
2+
* Default OG image — systematic isolation test.
3+
* Tests increasingly complex HTML to find the breaking point.
44
*/
55
import type { APIRoute } from "astro";
66
import { ImageResponse } from "workers-og";
@@ -9,20 +9,30 @@ import { generateDefaultOgHtml, loadFonts } from "../../../lib/og-utils";
99
export const prerender = false;
1010

1111
export const GET: APIRoute = async ({ url }) => {
12-
const mode = url.searchParams.get("mode") || "render";
13-
const title = url.searchParams.get("title") || "CodingCat.dev";
14-
const subtitle = url.searchParams.get("subtitle") || undefined;
12+
const level = url.searchParams.get("level") || "full";
1513

16-
const html = generateDefaultOgHtml({ title, subtitle });
14+
// Level 1: Single div (known working)
15+
const html1 = '<div style="display:flex;width:1200px;height:630px;background:#000;color:#fff;font-size:48px;align-items:center;justify-content:center">Hello World</div>';
1716

18-
// Mode: dump — return raw HTML for inspection
19-
if (mode === "dump") {
20-
return new Response(html, {
21-
headers: { "Content-Type": "text/plain" },
22-
});
17+
// Level 2: Two nested divs
18+
const html2 = '<div style="display:flex;width:1200px;height:630px;background:#000"><div style="display:flex;color:#fff;font-size:48px;align-items:center;justify-content:center;width:100%;height:100%">Hello World</div></div>';
19+
20+
// Level 3: Column layout with 3 children
21+
const html3 = '<div style="display:flex;width:1200px;height:630px;background:#000;padding:60px"><div style="display:flex;flex-direction:column;width:100%;height:100%;justify-content:space-between"><div style="display:flex;color:#fff;font-size:24px">Top</div><div style="display:flex;color:#fff;font-size:48px">Middle</div><div style="display:flex;color:#fff;font-size:16px">Bottom</div></div></div>';
22+
23+
// Level 4: Logo with emoji + spans
24+
const html4 = '<div style="display:flex;width:1200px;height:630px;background:#000;padding:60px"><div style="display:flex;flex-direction:column;width:100%;height:100%;justify-content:space-between"><div style="display:flex;align-items:center;gap:12px"><div style="font-size:40px">🐱</div><div style="display:flex;font-size:24px;font-weight:700;color:#fff"><span>CodingCat</span><span style="color:#7c3aed">.dev</span></div></div><div style="display:flex;color:#fff;font-size:48px">Title</div><div style="display:flex;color:#888;font-size:16px">codingcat.dev</div></div></div>';
25+
26+
// Level 5: Full template
27+
const html5 = generateDefaultOgHtml({ title: "Test Title" });
28+
29+
const htmlMap: Record<string, string> = { "1": html1, "2": html2, "3": html3, "4": html4, "5": html5, full: html5 };
30+
const html = htmlMap[level] || html5;
31+
32+
if (url.searchParams.get("mode") === "dump") {
33+
return new Response(html, { headers: { "Content-Type": "text/plain" } });
2334
}
2435

25-
// Mode: render — try to generate the image
2636
try {
2737
const response = new ImageResponse(html, {
2838
width: 1200,
@@ -32,22 +42,17 @@ export const GET: APIRoute = async ({ url }) => {
3242

3343
const buffer = await response.arrayBuffer();
3444
if (buffer.byteLength === 0) {
35-
return new Response(
36-
JSON.stringify({ error: "Empty buffer", htmlLength: html.length }),
37-
{ status: 500, headers: { "Content-Type": "application/json" } }
38-
);
45+
return new Response(JSON.stringify({ error: "Empty buffer", level }), {
46+
status: 500, headers: { "Content-Type": "application/json" },
47+
});
3948
}
4049

4150
return new Response(buffer, {
42-
headers: {
43-
"Content-Type": "image/png",
44-
"Content-Length": buffer.byteLength.toString(),
45-
},
51+
headers: { "Content-Type": "image/png", "Content-Length": buffer.byteLength.toString() },
4652
});
4753
} catch (e: any) {
48-
return new Response(
49-
JSON.stringify({ error: e.message, stack: e.stack }),
50-
{ status: 500, headers: { "Content-Type": "application/json" } }
51-
);
54+
return new Response(JSON.stringify({ error: e.message, level }), {
55+
status: 500, headers: { "Content-Type": "application/json" },
56+
});
5257
}
5358
};

0 commit comments

Comments
 (0)