-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathroute.tsx
More file actions
95 lines (85 loc) · 2.44 KB
/
route.tsx
File metadata and controls
95 lines (85 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { ImageResponse } from "next/og";
import type { NextRequest } from "next/server";
import { getPageImage, source } from "@/lib/geistdocs/source";
export const GET = async (
_request: NextRequest,
{ params }: RouteContext<"/[lang]/og/[...slug]">
) => {
const { slug, lang } = await params;
const page = source.getPage(slug.slice(0, -1), lang);
if (!page) {
return new Response("Not found", { status: 404 });
}
const { title, description } = page.data;
const regularFont = await readFile(
join(process.cwd(), "app/[lang]/og/[...slug]/geist-sans-regular.ttf")
);
const semiboldFont = await readFile(
join(process.cwd(), "app/[lang]/og/[...slug]/geist-sans-semibold.ttf")
);
const backgroundImage = await readFile(
join(process.cwd(), "app/[lang]/og/[...slug]/background.png")
);
const backgroundImageData = backgroundImage.buffer.slice(
backgroundImage.byteOffset,
backgroundImage.byteOffset + backgroundImage.byteLength
);
return new ImageResponse(
<div style={{ fontFamily: "Geist" }} tw="flex h-full w-full bg-black">
{/** biome-ignore lint/performance/noImgElement: "Required for Satori" */}
<img
alt="Vercel OpenGraph Background"
height={628}
src={backgroundImageData as never}
width={1200}
/>
<div tw="flex flex-col absolute h-full w-[750px] justify-center left-[50px] pr-[50px] pt-[116px] pb-[86px]">
<div
style={{
textWrap: "balance",
}}
tw="text-5xl font-medium text-white tracking-tight flex leading-[1.1] mb-4"
>
{title}
</div>
<div
style={{
color: "#8B8B8B",
lineHeight: "44px",
textWrap: "balance",
}}
tw="text-[32px]"
>
{description}
</div>
</div>
</div>,
{
width: 1200,
height: 628,
fonts: [
{
name: "Geist",
data: regularFont,
weight: 400,
},
{
name: "Geist",
data: semiboldFont,
weight: 500,
},
],
}
);
};
export const generateStaticParams = async ({
params,
}: RouteContext<"/[lang]/og/[...slug]">) => {
const { lang } = await params;
return source.getPages(lang).map((page) => ({
lang: page.locale,
slug: getPageImage(page).segments,
}));
};