1
1
import React from "react" ;
2
2
import { ImageResponse } from "next/og" ;
3
3
import type { NextApiRequest } from "next/index" ;
4
- import { TurboLogo } from "../../_components/logos/og/turbo -logo" ;
4
+ import { RepoLogo } from "../../_components/logos/og/repo -logo" ;
5
5
import { VercelLogo } from "../../_components/logos/og/vercel-logo" ;
6
6
import fs from "fs" ;
7
7
import path from "path" ;
8
8
9
9
export type Products = "repo" ;
10
10
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
-
21
11
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
+
22
34
const bgImagePath = path . join ( process . cwd ( ) , "app" , "api" , "og" , "bg.jpeg" ) ;
23
35
const bgImageBuffer = fs . readFileSync ( bgImagePath ) ;
24
36
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));
28
37
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
-
44
38
if ( ! req . url ) {
45
39
throw new Error ( "No URL was provided" ) ;
46
40
}
@@ -64,7 +58,7 @@ export async function GET(req: NextApiRequest): Promise<Response> {
64
58
justifyContent : "center" ,
65
59
width : "100%" ,
66
60
height : "100%" ,
67
- fontFamily : "Geist Mono " ,
61
+ fontFamily : "Geist Sans " ,
68
62
fontWeight : 700 ,
69
63
fontSize : 60 ,
70
64
backgroundImage : `url(${ bg } )` ,
@@ -76,12 +70,12 @@ export async function GET(req: NextApiRequest): Promise<Response> {
76
70
< div
77
71
style = { { display : "flex" , height : 97 * 1.1 , alignItems : "center" } }
78
72
>
79
- < TurboLogo height = { 97 * 1.1 } width = { 459 * 1.1 } />
73
+ < RepoLogo />
80
74
</ div >
81
75
{ title ? (
82
76
< div
83
77
style = { {
84
- fontFamily : "Geist Mono " ,
78
+ fontFamily : "Geist Sans " ,
85
79
fontSize : 36 ,
86
80
letterSpacing : - 1.5 ,
87
81
padding : "40px 20px 30px" ,
@@ -110,20 +104,20 @@ export async function GET(req: NextApiRequest): Promise<Response> {
110
104
</ div >
111
105
) ,
112
106
{
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
+ ] ,
127
121
}
128
122
) ;
129
123
} catch ( err : unknown ) {
0 commit comments