Skip to content

Commit b9c33d7

Browse files
committed
feat: add og image
1 parent bb9b6ea commit b9c33d7

4 files changed

Lines changed: 165 additions & 0 deletions

File tree

app/[lang]/layout.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Metadata } from "next";
12
import { staticLangParams } from "../../lib/lang.ts";
23
import { LangLayoutProps } from "../../lib/type.ts";
34
import "../globals.css";
@@ -8,6 +9,19 @@ export function generateStaticParams() {
89
return staticLangParams;
910
}
1011

12+
export async function generateMetadata({ params }: LangLayoutProps): Promise<Metadata> {
13+
const lang = (await params).lang;
14+
const title = lang === 'ja' ? 'ツールズ' : 'Tools';
15+
16+
return {
17+
title,
18+
openGraph: {
19+
title,
20+
images: `/${lang}/og.webp`,
21+
},
22+
};
23+
}
24+
1125
export default async function RootLayout({
1226
children,
1327
params,

app/[lang]/og.webp/route.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { ImageResponse } from 'next/og';
2+
3+
export function generateStaticParams() {
4+
return [
5+
{ lang: 'en' },
6+
{ lang: 'ja' },
7+
];
8+
}
9+
10+
export async function GET(_: Request, { params }: { params: Promise<{ lang: string }> }) {
11+
const lang = (await params).lang
12+
const text = lang === 'ja' ? 'ツールズ' : 'Tools';
13+
14+
return new ImageResponse(
15+
(
16+
<div
17+
style={{
18+
height: '100%',
19+
width: '100%',
20+
display: 'flex',
21+
flexDirection: 'column',
22+
alignItems: 'center',
23+
justifyContent: 'center',
24+
backgroundColor: '#0a0a0a',
25+
fontSize: 120,
26+
fontWeight: 700,
27+
color: 'white',
28+
}}
29+
>
30+
<div>
31+
{text}
32+
</div>
33+
</div>
34+
),
35+
{
36+
width: 1200,
37+
height: 630,
38+
}
39+
);
40+
}

deno.lock

Lines changed: 110 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"private": true,
33
"dependencies": {
44
"@radix-ui/react-icons": "1.3.2",
5+
"@vercel/og": "^0.8.5",
56
"next": "15.5.3",
67
"next-themes": "0.4.6",
78
"react": "19.1.1",

0 commit comments

Comments
 (0)