Skip to content

Commit d2108ae

Browse files
committed
Add opengraph-image
1 parent 7b9a384 commit d2108ae

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

src/app/opengraph-image.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ImageResponse } from "next/og";
2+
import { readFile } from "node:fs/promises";
3+
import { join } from "node:path";
4+
5+
export const alt = "Toska";
6+
export const size = {
7+
width: 1200,
8+
height: 630,
9+
};
10+
11+
export const contentType = "image/png";
12+
13+
export default async function Image() {
14+
const logoData = await readFile(
15+
join(process.cwd(), "public/assets/toska-logo.svg")
16+
);
17+
const logoBase64 = Buffer.from(logoData).toString("base64");
18+
const logoSrc = `data:image/svg+xml;base64,${logoBase64}`;
19+
20+
return new ImageResponse(
21+
(
22+
<div
23+
style={{
24+
display: "flex",
25+
alignItems: "center",
26+
justifyContent: "center",
27+
background: "#242124",
28+
height: "100%",
29+
width: "100%",
30+
}}
31+
>
32+
<img alt="Toska" src={logoSrc} height="50%" />
33+
</div>
34+
),
35+
{
36+
...size,
37+
}
38+
);
39+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { ImageResponse } from "next/og";
2+
import { readFile } from "node:fs/promises";
3+
import { join } from "node:path";
4+
5+
import { getProjectByName } from "@/lib/projects";
6+
7+
export const alt = "Toska";
8+
export const size = {
9+
width: 1200,
10+
height: 630,
11+
};
12+
13+
export const contentType = "image/png";
14+
15+
export default async function Image({ params }: { params: { name: string } }) {
16+
const logoData = await readFile(
17+
join(process.cwd(), "public/assets/toska-logo.svg")
18+
);
19+
const logoBase64 = Buffer.from(logoData).toString("base64");
20+
const logoSrc = `data:image/svg+xml;base64,${logoBase64}`;
21+
22+
const { name } = params;
23+
const project = await getProjectByName(name);
24+
const projectName = project?.title;
25+
26+
return new ImageResponse(
27+
(
28+
<div
29+
style={{
30+
display: "flex",
31+
flexDirection: "column",
32+
alignItems: "center",
33+
color: "#fff",
34+
justifyContent: "center",
35+
background: "#242124",
36+
height: "100%",
37+
width: "100%",
38+
}}
39+
>
40+
<img src={logoSrc} height="50%" />
41+
{projectName && <h1>{projectName}</h1>}
42+
</div>
43+
),
44+
{
45+
...size,
46+
}
47+
);
48+
}

0 commit comments

Comments
 (0)