feat(seo): per-locale OpenGraph image

When German visitors share a /de/ page on social media, the preview
card now shows the German tagline ("Metabolische Psychiatrie &
Systemische Longevity") instead of English. Same for French and
Italian.

Extracted the shared OG render to lib/og/element.tsx (so both the root
English fallback and the new per-locale image render the same layout
with only the tagline string differing). The new app/[locale]/
opengraph-image.tsx generates on demand at the edge from the existing
meta.tagline translation key.

Verified via curl: each locale emits a distinct PNG (file sizes differ
by tagline length); /de page metadata correctly references
/de/opengraph-image; Next.js auto-emits hreflang link headers across
locales with x-default pointing to the root.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
g-butandClaude Opus 4.7 committed 2026-04-25 17:14:57 +02:00
1 parent c8a430d5d6
commit c6dff54a7b
3 files changed
+130 -102

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
import { ImageResponse } from "next/og";
import { getTranslations } from "next-intl/server";
import { ogImageElement, OG_SIZE } from "@/lib/og/element";
// Per-locale OG image — German visitors sharing /de/ on social media see a
// German tagline, French visitors see French, etc. Generated on demand at the
// edge from the meta.tagline translation key (single source of truth).
export const runtime = "edge";
export const size = OG_SIZE;
export const contentType = "image/png";
type Props = { params: Promise<{ locale: string }> };
export default async function OgImage({ params }: Props) {
const { locale } = await params;
const t = await getTranslations({ locale, namespace: "meta" });
return new ImageResponse(ogImageElement({ tagline: t("tagline") }), { ...size });
}
+7 -102
View File
@@ -1,112 +1,17 @@
import { ImageResponse } from "next/og";
import { COLOR_INK, COLOR_OFF, COLOR_TEAL } from "@/lib/config/theme";
import { COMPANY } from "@/lib/config/company";
import { ogImageElement, OG_SIZE } from "@/lib/og/element";
// Default English fallback OG image (used by non-locale routes).
// Locale-prefixed pages get their own image from app/[locale]/opengraph-image.tsx.
export const runtime = "edge";
export const alt = "VitaReBa · Metabolic Psychiatry & Systemic Longevity · Zürich";
export const size = { width: 1200, height: 630 };
export const alt = `${COMPANY.shortName} · Metabolic Psychiatry & Systemic Longevity · ${COMPANY.address.city}`;
export const size = OG_SIZE;
export const contentType = "image/png";
export default function OgImage() {
return new ImageResponse(
(
<div
style={{
background: COLOR_INK,
width: "100%",
height: "100%",
display: "flex",
flexDirection: "column",
justifyContent: "center",
padding: "80px",
fontFamily: "sans-serif",
}}
>
{/* Teal accent line */}
<div
style={{
position: "absolute",
top: 0,
left: 0,
right: 0,
height: "4px",
background: COLOR_TEAL,
}}
/>
{/* Eyebrow */}
<div
style={{
fontSize: 16,
letterSpacing: "0.3em",
textTransform: "uppercase",
color: "rgba(42,122,138,0.8)",
marginBottom: 24,
display: "flex",
}}
>
Zürich · Switzerland
</div>
{/* Logo */}
<div
style={{
fontSize: 64,
fontWeight: 300,
color: COLOR_OFF,
lineHeight: 1.1,
marginBottom: 24,
display: "flex",
}}
>
Vita
<span style={{ color: COLOR_TEAL }}>Re</span>
Ba
</div>
{/* Tagline */}
<div
style={{
fontSize: 28,
fontWeight: 300,
color: "rgba(255,255,255,0.55)",
lineHeight: 1.4,
maxWidth: 700,
display: "flex",
}}
>
Metabolic Psychiatry & Systemic Longevity
</div>
{/* Pills */}
<div
style={{
display: "flex",
gap: 12,
marginTop: 40,
}}
>
{["ADHD", "Longevity", "Psychedelic Therapy", "High Performance"].map(
(pill) => (
<div
key={pill}
style={{
fontSize: 13,
letterSpacing: "0.12em",
textTransform: "uppercase",
padding: "8px 16px",
background: "rgba(42,122,138,0.12)",
color: COLOR_TEAL,
borderRadius: 20,
display: "flex",
}}
>
{pill}
</div>
)
)}
</div>
</div>
),
ogImageElement({ tagline: "Metabolic Psychiatry & Systemic Longevity" }),
{ ...size }
);
}
+105
View File
@@ -0,0 +1,105 @@
// Shared OG-image render — used by both app/opengraph-image.tsx (default English
// fallback) and app/[locale]/opengraph-image.tsx (per-locale tagline).
// Kept in /lib so it stays separate from the route-segment file convention.
import { COLOR_INK, COLOR_OFF, COLOR_TEAL } from "@/lib/config/theme";
import { COMPANY } from "@/lib/config/company";
const PILLS = ["ADHD", "Longevity", "Psychedelic Therapy", "High Performance"];
export function ogImageElement({ tagline }: { tagline: string }) {
return (
<div
style={{
background: COLOR_INK,
width: "100%",
height: "100%",
display: "flex",
flexDirection: "column",
justifyContent: "center",
padding: "80px",
fontFamily: "sans-serif",
}}
>
<div
style={{
position: "absolute",
top: 0,
left: 0,
right: 0,
height: "4px",
background: COLOR_TEAL,
}}
/>
<div
style={{
fontSize: 16,
letterSpacing: "0.3em",
textTransform: "uppercase",
color: "rgba(42,122,138,0.8)",
marginBottom: 24,
display: "flex",
}}
>
{COMPANY.address.city} · Switzerland
</div>
<div
style={{
fontSize: 64,
fontWeight: 300,
color: COLOR_OFF,
lineHeight: 1.1,
marginBottom: 24,
display: "flex",
}}
>
Vita
<span style={{ color: COLOR_TEAL }}>Re</span>
Ba
</div>
<div
style={{
fontSize: 28,
fontWeight: 300,
color: "rgba(255,255,255,0.55)",
lineHeight: 1.4,
maxWidth: 700,
display: "flex",
}}
>
{tagline}
</div>
<div
style={{
display: "flex",
gap: 12,
marginTop: 40,
}}
>
{PILLS.map((pill) => (
<div
key={pill}
style={{
fontSize: 13,
letterSpacing: "0.12em",
textTransform: "uppercase",
padding: "8px 16px",
background: "rgba(42,122,138,0.12)",
color: COLOR_TEAL,
borderRadius: 20,
display: "flex",
}}
>
{pill}
</div>
))}
</div>
</div>
);
}
export const OG_SIZE = { width: 1200, height: 630 } as const;