Skip to content

Commit 6eb8a85

Browse files
committed
feat: add generated og card for as it should be
- og card: generated with the tool-card renderer and the game banner uncropped, replacing the distorted static jpg - metadata: twitter title and description aligned on the game page, json-ld image points to the generated route - og renderer: line icons and configurable preview width, tool cards unchanged
1 parent 56fe577 commit 6eb8a85

7 files changed

Lines changed: 101 additions & 15 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ InfraLens changes since its native migration are recorded here.
2323
one exists.
2424
- **Privacy page for As It Should Be** — bilingual, provisional, and kept out
2525
of search indexing until its content is verified against the final build.
26+
- **Generated social card for As It Should Be** — same visual language as
27+
the tool cards, with the game banner shown uncropped, and matching Twitter
28+
title and description.
2629

2730
### Changed
2831

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { renderToolOgImage } from "@/components/og/tool-og-image";
2+
import { brand } from "@/lib/brand";
3+
import { getGame } from "@/lib/games";
4+
import { readFile } from "node:fs/promises";
5+
import { join } from "node:path";
6+
7+
export const runtime = "nodejs";
8+
export const alt = "As It Should Be — Randy Code";
9+
export const size = { width: 1200, height: 630 };
10+
export const contentType = "image/png";
11+
12+
// Raw node data from lucide-react's gamepad-2 icon
13+
// (dist/esm/icons/gamepad-2.mjs), with Lucide's internal `key` field dropped.
14+
const GAMEPAD_ICON = [
15+
["line", { x1: "6", x2: "10", y1: "11", y2: "11" }],
16+
["line", { x1: "8", x2: "8", y1: "9", y2: "13" }],
17+
["line", { x1: "15", x2: "15.01", y1: "12", y2: "12" }],
18+
["line", { x1: "18", x2: "18.01", y1: "10", y2: "10" }],
19+
[
20+
"path",
21+
{
22+
d: "M17.32 5H6.68a4 4 0 0 0-3.978 3.59c-.006.052-.01.101-.017.152C2.604 9.416 2 14.456 2 16a3 3 0 0 0 3 3c1 0 1.5-.5 2-1l1.414-1.414A2 2 0 0 1 9.828 16h4.344a2 2 0 0 1 1.414.586L17 18c.5.5 1 1 2 1a3 3 0 0 0 3-3c0-1.545-.604-6.584-.685-7.258-.007-.05-.011-.1-.017-.151A4 4 0 0 0 17.32 5z",
23+
},
24+
],
25+
] as const;
26+
27+
const PANEL_WIDTH = 440;
28+
const BANNER_WIDTH = PANEL_WIDTH - 56;
29+
30+
export default async function Image() {
31+
const game = getGame("as-it-should-be");
32+
if (!game) throw new Error("Game not found");
33+
34+
const banner = await readFile(join(process.cwd(), "public", game.banner.src));
35+
const bannerHeight = Math.round(
36+
(BANNER_WIDTH * game.banner.height) / game.banner.width,
37+
);
38+
39+
const preview = (
40+
<div
41+
style={{
42+
display: "flex",
43+
width: BANNER_WIDTH,
44+
height: bannerHeight,
45+
borderRadius: 12,
46+
overflow: "hidden",
47+
}}
48+
>
49+
<img
50+
src={`data:image/jpeg;base64,${banner.toString("base64")}`}
51+
width={BANNER_WIDTH}
52+
height={bannerHeight}
53+
alt=""
54+
/>
55+
</div>
56+
);
57+
58+
return renderToolOgImage({
59+
title: game.name,
60+
tagline: game.tagline.fr,
61+
color: brand.colors.violet[400],
62+
iconNodes: GAMEPAD_ICON,
63+
label: "Games Arcade",
64+
preview,
65+
previewWidth: PANEL_WIDTH,
66+
});
67+
}

‎app/games/as-it-should-be/page.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ export const metadata: Metadata = {
2626
"Placer les pièces, lancer la réaction. Un puzzle tactile de logique, en phase de test.",
2727
url: "/games/as-it-should-be",
2828
type: "website",
29-
images: [
30-
{ url: "/games/as-it-should-be/og.jpg", width: 1200, height: 630 },
31-
],
29+
},
30+
twitter: {
31+
card: "summary_large_image",
32+
title: "As It Should Be — Puzzle mobile",
33+
description:
34+
"Placer les pièces, lancer la réaction. Un puzzle tactile de logique, en phase de test.",
3235
},
3336
};
3437

-141 KB
Binary file not shown.

‎src/components/og/tool-og-image.tsx‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import type { ReactNode } from "react";
66
const SIZE = { width: 1200, height: 630 };
77

88
/** A single Lucide `__iconNode` entry, stripped of its internal `key` field — see the note in each tool's opengraph-image.tsx. */
9-
export type IconNode = readonly ["circle" | "path", Record<string, string>];
9+
export type IconNode = readonly [
10+
"circle" | "path" | "line",
11+
Record<string, string>,
12+
];
1013

1114
/**
1215
* Renders a Lucide icon from its raw node data rather than the React
@@ -38,13 +41,23 @@ export function Icon({
3841
strokeLinejoin="round"
3942
style={{ display: "flex" }}
4043
>
41-
{nodes.map(([tag, attrs], index) =>
42-
tag === "circle" ? (
43-
<circle key={index} cx={attrs.cx} cy={attrs.cy} r={attrs.r} />
44-
) : (
45-
<path key={index} d={attrs.d} />
46-
),
47-
)}
44+
{nodes.map(([tag, attrs], index) => {
45+
if (tag === "circle") {
46+
return <circle key={index} cx={attrs.cx} cy={attrs.cy} r={attrs.r} />;
47+
}
48+
if (tag === "line") {
49+
return (
50+
<line
51+
key={index}
52+
x1={attrs.x1}
53+
y1={attrs.y1}
54+
x2={attrs.x2}
55+
y2={attrs.y2}
56+
/>
57+
);
58+
}
59+
return <path key={index} d={attrs.d} />;
60+
})}
4861
</svg>
4962
);
5063
}
@@ -64,6 +77,7 @@ export async function renderToolOgImage({
6477
iconNodes,
6578
label,
6679
preview,
80+
previewWidth = 380,
6781
}: {
6882
title: string;
6983
tagline: string;
@@ -79,6 +93,7 @@ export async function renderToolOgImage({
7993
* without a preview yet keep the original full-width single-column
8094
* layout. */
8195
preview?: ReactNode;
96+
previewWidth?: number;
8297
}) {
8398
const [fontBold, fontRegular] = await Promise.all([
8499
readFile(join(process.cwd(), "assets/Inter-Bold.woff")),
@@ -238,7 +253,7 @@ export async function renderToolOgImage({
238253
display: "flex",
239254
flexDirection: "column",
240255
justifyContent: "center",
241-
width: 380,
256+
width: previewWidth,
242257
flexShrink: 0,
243258
}}
244259
>

‎src/lib/games.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export interface Game {
1515
symbol: { src: string; alt: string };
1616
technologies: string[];
1717
banner: { src: string; width: number; height: number };
18-
ogImage: string;
1918
stores: { googlePlay?: string; appStore?: string };
2019
privacyReviewed: boolean;
2120
}
@@ -43,7 +42,6 @@ export const games: Game[] = [
4342
width: 1932,
4443
height: 814,
4544
},
46-
ogImage: "/games/as-it-should-be/og.jpg",
4745
stores: {},
4846
privacyReviewed: false,
4947
},

‎src/lib/json-ld.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function buildVideoGameSchema(game: Game) {
8787
name: game.name,
8888
description: game.summary.fr,
8989
url: `https://randy-code.dev/games/${game.slug}`,
90-
image: `https://randy-code.dev${game.ogImage}`,
90+
image: `https://randy-code.dev/games/${game.slug}/opengraph-image`,
9191
genre: game.genre.en,
9292
inLanguage: ["fr", "en"],
9393
author: {

0 commit comments

Comments
 (0)