Skip to content

Commit b36cbf9

Browse files
Miriadseniordeveloper
andcommitted
fix: minify OG HTML templates to eliminate whitespace text nodes
Satori's HTML parser (via HTMLRewriter) treats whitespace between elements as text nodes. Template literal formatting creates newlines and indentation that become phantom children, violating Satori's strict "display: flex" requirement even when the div already has it. Added minifyHtml() helper that strips whitespace between tags (/>\\s+</g -> "><"). Applied to both generateOgHtml and generateDefaultOgHtml return values. Templates stay readable, output is minified. Build: 18.23s ✅ Co-authored-by: seniordeveloper <seniordeveloper@miriad.systems>
1 parent b27f96c commit b36cbf9

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

apps/web/src/lib/og-utils.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ export function loadFonts() {
6565
];
6666
}
6767

68+
// ── Minify HTML for Satori ───────────────────────────────────────────
69+
// Satori's HTML parser (via HTMLRewriter) treats whitespace between
70+
// elements as text nodes. Template literal formatting creates phantom
71+
// text nodes that violate Satori's strict "display: flex" requirement.
72+
function minifyHtml(html: string): string {
73+
return html.replace(/>\s+</g, "><").trim();
74+
}
75+
6876
// ── Adaptive title font size ─────────────────────────────────────────
6977
export function titleFontSize(title: string): number {
7078
if (title.length > 60) return 42;
@@ -133,7 +141,7 @@ export function generateOgHtml({
133141
</div>
134142
`;
135143

136-
return `
144+
return minifyHtml(`
137145
<div style="
138146
display: flex;
139147
width: 1200px;
@@ -206,7 +214,7 @@ export function generateOgHtml({
206214
</div>
207215
</div>
208216
</div>
209-
`;
217+
`);
210218
}
211219

212220
/**
@@ -232,7 +240,7 @@ export function generateDefaultOgHtml({
232240
">${subtitle}</div>`
233241
: "";
234242

235-
return `
243+
return minifyHtml(`
236244
<div style="
237245
display: flex;
238246
width: 1200px;
@@ -285,5 +293,5 @@ export function generateDefaultOgHtml({
285293
</div>
286294
</div>
287295
</div>
288-
`;
296+
`);
289297
}

0 commit comments

Comments
 (0)