Skip to content

Commit e4cbd89

Browse files
committed
fix: social share og
1 parent f1e1209 commit e4cbd89

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

bitext/src/routes/+page.svelte

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,19 @@
5555
});
5656
5757
const origin = $derived(page.url.origin);
58+
const dataParam = $derived(page.url.searchParams.get('data'));
5859
const ogImage = $derived.by(() => {
59-
const p = page.url.searchParams.get('data');
60-
if (p) return `${origin}/api/og?data=${encodeURIComponent(p)}`;
60+
if (dataParam) return `${origin}/api/og?data=${encodeURIComponent(dataParam)}`;
6161
return `${origin}/api/og`;
6262
});
63-
const canonical = $derived(page.url.origin + page.url.pathname);
63+
// Canonical / og:url must include the `?data=...` payload when present.
64+
// Without it, Facebook resolves each shared URL back to the bare landing page, reuses its
65+
// cached og:image (the generic preview), and never shows the visualization for the actual
66+
// share. Each `?data=...` URL is a distinct shareable view and deserves its own canonical.
67+
const canonical = $derived.by(() => {
68+
const base = page.url.origin + page.url.pathname;
69+
return dataParam ? `${base}?data=${encodeURIComponent(dataParam)}` : base;
70+
});
6471
6572
const authorSite = 'https://danipolani.github.io/en/';
6673
const toolsPage = 'https://danipolani.github.io/en/blog/tools/';
@@ -77,6 +84,7 @@
7784
<meta property="og:description" content={DEFAULT_DESCRIPTION} />
7885
<meta property="og:url" content={canonical} />
7986
<meta property="og:image" content={ogImage} />
87+
<meta property="og:image:secure_url" content={ogImage} />
8088
<meta property="og:image:type" content="image/png" />
8189
<meta property="og:image:width" content="1200" />
8290
<meta property="og:image:height" content="630" />

bitext/src/routes/api/og/+server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export const GET: RequestHandler = async ({ url }) => {
1414
mode: 'width',
1515
value: OG_IMAGE_WIDTH
1616
},
17+
// Opaque canvas — some social scrapers (Facebook's in particular) render PNGs with alpha
18+
// as a blank dark rectangle in their preview widget even when the pixels are fully opaque.
19+
background: '#0f172a',
1720
font: {
1821
fontFiles,
1922
loadSystemFonts: false,
@@ -25,6 +28,7 @@ export const GET: RequestHandler = async ({ url }) => {
2528
return new Response(new Uint8Array(buffer), {
2629
headers: {
2730
'Content-Type': 'image/png',
31+
'Content-Length': String(buffer.length),
2832
'Cache-Control': 'public, max-age=3600'
2933
}
3034
});

0 commit comments

Comments
 (0)