Skip to content

Commit e702897

Browse files
author
Miriad
committed
debug: isolate emoji vs spans — 5 logo variants via ?v=1-5
1 parent 1cd57c0 commit e702897

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

apps/web/src/pages/api/og/default.png.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,56 @@
11
/**
2-
* Default OG image — bypass HTMLRewriter by using React elements directly.
3-
* workers-og's og() accepts React.ReactNode, skipping parseHtml entirely.
2+
* Default OG image — isolate emoji vs spans in logo row.
43
*/
54
import type { APIRoute } from "astro";
65
import { ImageResponse } from "workers-og";
76
import { loadFonts } from "../../../lib/og-utils";
87

98
export const prerender = false;
109

10+
const base = (inner: string) =>
11+
`<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">${inner}<div style="display:flex;color:#fff;font-size:48px">Title</div><div style="display:flex;color:#888;font-size:16px">Footer</div></div></div>`;
12+
1113
export const GET: APIRoute = async ({ url }) => {
14+
const variant = url.searchParams.get("v") || "1";
15+
16+
const variants: Record<string, string> = {
17+
// 1: Just text, no emoji, no spans
18+
"1": base('<div style="display:flex;align-items:center;gap:12px"><div style="color:#fff;font-size:24px">CodingCat.dev</div></div>'),
19+
// 2: Emoji only (is HTMLRewriter chunking the emoji?)
20+
"2": base('<div style="display:flex;align-items:center;gap:12px"><div style="font-size:40px">🐱</div><div style="color:#fff;font-size:24px">CodingCat.dev</div></div>'),
21+
// 3: Spans only, no emoji
22+
"3": base('<div style="display:flex;align-items:center;gap:12px"><div style="display:flex;font-size:24px;color:#fff"><span>CodingCat</span><span style="color:#7c3aed">.dev</span></div></div>'),
23+
// 4: Emoji + spans (full logo)
24+
"4": base('<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>'),
25+
// 5: ASCII cat instead of emoji
26+
"5": base('<div style="display:flex;align-items:center;gap:12px"><div style="font-size:40px">CC</div><div style="display:flex;font-size:24px;font-weight:700;color:#fff"><span>CodingCat</span><span style="color:#7c3aed">.dev</span></div></div>'),
27+
};
28+
29+
const html = variants[variant] || variants["1"];
30+
31+
if (url.searchParams.get("mode") === "dump") {
32+
return new Response(html, { headers: { "Content-Type": "text/plain" } });
33+
}
34+
1235
try {
13-
// Pass a React element directly — bypasses HTMLRewriter parseHtml
14-
const element = {
15-
type: "div",
16-
props: {
17-
style: {
18-
display: "flex",
19-
width: 1200,
20-
height: 630,
21-
background: "#000",
22-
color: "#fff",
23-
fontSize: 48,
24-
alignItems: "center",
25-
justifyContent: "center",
26-
},
27-
children: "Hello World",
28-
},
29-
};
30-
31-
const response = new ImageResponse(element as any, {
36+
const response = new ImageResponse(html, {
3237
width: 1200,
3338
height: 630,
3439
fonts: loadFonts(),
3540
});
3641

3742
const buffer = await response.arrayBuffer();
3843
if (buffer.byteLength === 0) {
39-
return new Response(JSON.stringify({ error: "Empty buffer" }), {
44+
return new Response(JSON.stringify({ error: "Empty buffer", variant }), {
4045
status: 500, headers: { "Content-Type": "application/json" },
4146
});
4247
}
4348

4449
return new Response(buffer, {
45-
headers: {
46-
"Content-Type": "image/png",
47-
"Content-Length": buffer.byteLength.toString(),
48-
},
50+
headers: { "Content-Type": "image/png", "Content-Length": buffer.byteLength.toString() },
4951
});
5052
} catch (e: any) {
51-
return new Response(JSON.stringify({ error: e.message, stack: e.stack }), {
53+
return new Response(JSON.stringify({ error: e.message, variant }), {
5254
status: 500, headers: { "Content-Type": "application/json" },
5355
});
5456
}

0 commit comments

Comments
 (0)