Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 07:15 UTC
fix(docs): center single-word OG image titles
Satori's textWrap: 'balance' shrinks the measured box of text that cannot wrap, so single-word titles drew wider than their box and flex centering shifted them right (Firewall: +62px). Balance only text containing whitespace, keeping balanced multi-line titles and descriptions. Refs DES-3273
Brendan O'Leary committed
Oct 26, 2026 at 14:17 UTC
2bf060f992a00fdd67efe91c3456cbefa45fd2e3
3 files changed
+73
-2
docs/README.md
+4
@@ -28,6 +28,10 @@ docs/
28
└── public/ # Static assets
29
```
30
31
+## Social Preview Images
32
+
33
+`app/api/og/route.tsx` renders `/api/og` cards. Titles and descriptions apply `textWrap: 'balance'` only when they contain whitespace: Satori undermeasures balanced text that cannot wrap, which shifts single-word titles right. Preview with `/api/og?title=Firewall&description=Block+tool+calls+and+tool+results+you+don%27t+want+your+agent+to+act+on`; add `theme=light` for the light variant.
34
+
35
## Adding Content
36
37
Create an `.mdx` file in `content/`, add frontmatter, then add to `meta.json`:
docs/app/api/og/route.tsx
+10
-2
@@ -208,12 +208,20 @@ function Chip({ children, c }: { children: string; c: Palette }) {
208
);
209
}
210
211
+// Satori balances by shrinking the measured box until the line count would
212
+// grow. Text with no break opportunity never wraps, so the box shrinks below
213
+// the drawn glyphs and flex centering shifts the text right. Balance only
214
+// text that can actually wrap.
215
+function balanceIfBreakable(text: string) {
216
+ return /\s/.test(text) ? ({ textWrap: 'balance' } as const) : {};
217
+}
218
+
219
function Title({ children, size, c }: { children: string; size: number; c: Palette }) {
220
return (
221
<div style={{
222
display: 'flex', fontFamily: sans, fontWeight: 500, fontSize: size, lineHeight: 1.08,
223
letterSpacing: size >= 60 ? -2 : -1.2, color: c.ink, maxWidth: 1000, lineClamp: 3,
216
- justifyContent: 'center', textAlign: 'center', textWrap: 'balance',
224
+ justifyContent: 'center', textAlign: 'center', ...balanceIfBreakable(children),
225
}}>
226
{children}
227
</div>
@@ -233,7 +241,7 @@ function Description({ children, c }: { children: string; c: Palette }) {
241
return (
242
<div style={{
243
display: 'flex', fontFamily: sans, fontSize: 30, lineHeight: 1.4, color: c.soft, maxWidth: 900, lineClamp: 2,
236
- justifyContent: 'center', textAlign: 'center', textWrap: 'balance',
244
+ justifyContent: 'center', textAlign: 'center', ...balanceIfBreakable(children),
245
}}>
246
{children}
247
</div>
docs/tests/static/og-image.test.ts
+59
@@ -1,4 +1,5 @@
1
import { expect, test } from 'bun:test';
2
+import { inflateSync } from 'node:zlib';
3
import { GET, parseOgParams, toolkitCardTitle } from '../../app/api/og/route';
4
import { getOgImageUrl } from '../../lib/source';
5
import { HOME_OG_DESCRIPTION } from '../../lib/toolkit-count';
@@ -13,6 +14,64 @@ async function expectPng(url: string) {
14
expect(bytes.readUInt32BE(20)).toBe(630);
15
}
16
17
+/** Decodes the route's 8-bit RGB/RGBA PNG output into unfiltered pixel rows. */
18
+function decodePng(bytes: Buffer) {
19
+ const width = bytes.readUInt32BE(16);
20
+ const height = bytes.readUInt32BE(20);
21
+ const [depth, colorType] = [bytes[24], bytes[25]];
22
+ expect(depth).toBe(8);
23
+ expect([2, 6]).toContain(colorType);
24
+ const channels = colorType === 6 ? 4 : 3;
25
+ const chunks: Buffer[] = [];
26
+ for (let at = 8; at < bytes.length; ) {
27
+ const length = bytes.readUInt32BE(at);
28
+ if (bytes.toString('ascii', at + 4, at + 8) === 'IDAT') chunks.push(bytes.subarray(at + 8, at + 8 + length));
29
+ at += length + 12;
30
+ }
31
+ const raw = inflateSync(Buffer.concat(chunks));
32
+ const stride = width * channels;
33
+ const pixels = Buffer.alloc(height * stride);
34
+ for (let y = 0; y < height; y++) {
35
+ const filter = raw[y * (stride + 1)];
36
+ for (let x = 0; x < stride; x++) {
37
+ const value = raw[y * (stride + 1) + 1 + x];
38
+ const left = x >= channels ? pixels[y * stride + x - channels] : 0;
39
+ const up = y > 0 ? pixels[(y - 1) * stride + x] : 0;
40
+ const upLeft = y > 0 && x >= channels ? pixels[(y - 1) * stride + x - channels] : 0;
41
+ const p = left + up - upLeft;
42
+ const [pa, pb, pc] = [Math.abs(p - left), Math.abs(p - up), Math.abs(p - upLeft)];
43
+ const predictor = [0, left, up, (left + up) >> 1, pa <= pb && pa <= pc ? left : pb <= pc ? up : upLeft][filter];
44
+ pixels[y * stride + x] = (value + predictor) & 0xff;
45
+ }
46
+ }
47
+ return { width, height, channels, pixels };
48
+}
49
+
50
+/** Horizontal center of the dark title glyphs below the header row. */
51
+async function titleCenter(title: string) {
52
+ const response = await GET(new Request(`https://docs.composio.dev/api/og?theme=light&title=${encodeURIComponent(title)}`));
53
+ const { width, height, channels, pixels } = decodePng(Buffer.from(await response.arrayBuffer()));
54
+ let [left, right] = [width, -1];
55
+ for (let y = 150; y < height; y++) {
56
+ for (let x = 0; x < width; x++) {
57
+ const at = (y * width + x) * channels;
58
+ if (pixels[at] < 90 && pixels[at + 1] < 90 && pixels[at + 2] < 90) {
59
+ left = Math.min(left, x);
60
+ right = Math.max(right, x);
61
+ }
62
+ }
63
+ }
64
+ expect(right).toBeGreaterThan(left);
65
+ return (left + right) / 2;
66
+}
67
+
68
+test('titles render horizontally centered whether or not they can wrap', async () => {
69
+ // Single words cannot wrap; balanced wrapping once pushed them ~100px right.
70
+ for (const title of ['Firewall', 'Introduction', 'Tool Router']) {
71
+ expect(Math.abs((await titleCenter(title)) - 600)).toBeLessThan(15);
72
+ }
73
+});
74
+
75
test('docs host renders a PNG for the advertised title URL', async () => {
76
for (const title of ['Welcome', 'Authentication & OAuth / setup', 'Very long title '.repeat(20), '']) {
77
const url = getOgImageUrl('docs', ['authentication'], title);