Skip to content

Commit 2d9015d

Browse files
committed
Beautiful.
1 parent f3a813a commit 2d9015d

File tree

2 files changed

+146
-137
lines changed

2 files changed

+146
-137
lines changed

docs/site/app/api/og/route.tsx

+40-46
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
11
import React from "react";
22
import { ImageResponse } from "next/og";
33
import type { NextApiRequest } from "next/index";
4-
import { TurboLogo } from "../../_components/logos/og/turbo-logo";
4+
import { RepoLogo } from "../../_components/logos/og/repo-logo";
55
import { VercelLogo } from "../../_components/logos/og/vercel-logo";
66
import fs from "fs";
77
import path from "path";
88

99
export type Products = "repo";
1010

11-
function _arrayBufferToBase64(buffer: ArrayBuffer): string {
12-
let binary = "";
13-
const bytes = new Uint8Array(buffer);
14-
const len = bytes.byteLength;
15-
for (let i = 0; i < len; i++) {
16-
binary += String.fromCharCode(bytes[i]);
17-
}
18-
return btoa(binary);
19-
}
20-
2111
export async function GET(req: NextApiRequest): Promise<Response> {
12+
const fontPath = path.join(
13+
process.cwd(),
14+
"node_modules",
15+
"geist",
16+
"dist",
17+
"fonts",
18+
"geist-sans",
19+
"Geist-Regular.ttf"
20+
);
21+
const geistSans = fs.readFileSync(fontPath);
22+
23+
const fontMonoPath = path.join(
24+
process.cwd(),
25+
"node_modules",
26+
"geist",
27+
"dist",
28+
"fonts",
29+
"geist-mono",
30+
"GeistMono-Regular.ttf"
31+
);
32+
const geistMono = fs.readFileSync(fontMonoPath);
33+
2234
const bgImagePath = path.join(process.cwd(), "app", "api", "og", "bg.jpeg");
2335
const bgImageBuffer = fs.readFileSync(bgImagePath);
2436
const bg = `data:image/jpeg;base64,${bgImageBuffer.toString("base64")}`;
25-
// const url = new URL("bg.jpeg", import.meta.url);
26-
// console.log(url);
27-
// console.log(await fetch(url));
2837
try {
29-
// const [bg] = await Promise.all([
30-
// fetch(new URL("./Geist-Regular.ttf", import.meta.url)).then((res) =>
31-
// res.arrayBuffer()
32-
// ),
33-
// fetch(new URL("./GeistMono-Regular.ttf", import.meta.url)).then((res) =>
34-
// res.arrayBuffer()
35-
// ),
36-
// _arrayBufferToBase64(
37-
// // await fetch(new URL("./bg.jpeg", import.meta.url)).then((res) =>
38-
// await fetch(new URL("./bg.jpeg", import.meta.url)).then((res) =>
39-
// res.arrayBuffer()
40-
// )
41-
// ),
42-
// ]);
43-
4438
if (!req.url) {
4539
throw new Error("No URL was provided");
4640
}
@@ -64,7 +58,7 @@ export async function GET(req: NextApiRequest): Promise<Response> {
6458
justifyContent: "center",
6559
width: "100%",
6660
height: "100%",
67-
fontFamily: "Geist Mono",
61+
fontFamily: "Geist Sans",
6862
fontWeight: 700,
6963
fontSize: 60,
7064
backgroundImage: `url(${bg})`,
@@ -76,12 +70,12 @@ export async function GET(req: NextApiRequest): Promise<Response> {
7670
<div
7771
style={{ display: "flex", height: 97 * 1.1, alignItems: "center" }}
7872
>
79-
<TurboLogo height={97 * 1.1} width={459 * 1.1} />
73+
<RepoLogo />
8074
</div>
8175
{title ? (
8276
<div
8377
style={{
84-
fontFamily: "Geist Mono",
78+
fontFamily: "Geist Sans",
8579
fontSize: 36,
8680
letterSpacing: -1.5,
8781
padding: "40px 20px 30px",
@@ -110,20 +104,20 @@ export async function GET(req: NextApiRequest): Promise<Response> {
110104
</div>
111105
),
112106
{
113-
// fonts: [
114-
// {
115-
// name: "Geist Mono",
116-
// data: geistMono,
117-
// weight: 700 as const,
118-
// style: "normal" as const,
119-
// },
120-
// {
121-
// name: "Geist Sans",
122-
// data: geist,
123-
// weight: 400 as const,
124-
// style: "normal" as const,
125-
// },
126-
// ],
107+
fonts: [
108+
{
109+
name: "Geist Mono",
110+
data: geistMono,
111+
weight: 700 as const,
112+
style: "normal" as const,
113+
},
114+
{
115+
name: "Geist Sans",
116+
data: geistSans,
117+
weight: 400 as const,
118+
style: "normal" as const,
119+
},
120+
],
127121
}
128122
);
129123
} catch (err: unknown) {

0 commit comments

Comments
 (0)