-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathopengraph-image.tsx
More file actions
173 lines (165 loc) · 4.31 KB
/
opengraph-image.tsx
File metadata and controls
173 lines (165 loc) · 4.31 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { getUserByUsername } from "@/backend/services/user.action";
import getFileUrl from "@/utils/getFileUrl";
import { sanitizedUsername } from "@/lib/utils";
import { ImageResponse } from "next/og";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
interface ProfilePageProps {
params: Promise<{
username: string;
}>;
}
export const size = {
width: 1200,
height: 630,
};
export const contentType = "image/png";
const getFileLocation = async (relativePath: string) => {
const fileData = await readFile(join(process.cwd(), "public", relativePath));
return Uint8Array.from(fileData).buffer;
};
export default async function Image(options: ProfilePageProps) {
const { username } = await options.params;
const sanitized = sanitizedUsername(username);
const profile = await getUserByUsername(sanitized, [
"name",
"username",
"bio",
"profile_photo",
"designation",
]);
const displayName = profile?.name ?? sanitized;
const displayUsername = profile?.username ?? sanitized;
const bio = profile?.bio ?? null;
const designation = profile?.designation ?? null;
const profilePhotoUrl = profile?.profile_photo
? getFileUrl(profile.profile_photo)
: null;
return new ImageResponse(
(
<div
style={{
background: "white",
fontFamily: "BANGLA_FONT",
fontWeight: 400,
display: "flex",
flexDirection: "column",
justifyContent: "space-between",
height: "100%",
width: "100%",
}}
>
{/* Main content area */}
<div
style={{
display: "flex",
flex: 1,
background: "rgb(54%, 61%, 100%)",
alignItems: "center",
justifyContent: "center",
padding: 40,
gap: 40,
}}
>
{/* Profile photo */}
{profilePhotoUrl ? (
<img
src={profilePhotoUrl}
alt={displayName}
style={{
width: 160,
height: 160,
borderRadius: "50%",
objectFit: "cover",
border: "4px solid white",
flexShrink: 0,
}}
/>
) : null}
{/* Text info */}
<div
style={{
display: "flex",
flexDirection: "column",
gap: 12,
color: "white",
}}
>
<h1
style={{
fontSize: 52,
margin: 0,
fontFamily: "BANGLA_FONT",
lineHeight: 1.2,
}}
>
{displayName}
</h1>
<p
style={{
fontSize: 28,
margin: 0,
opacity: 0.85,
}}
>
@{displayUsername}
</p>
{designation ? (
<p
style={{
fontSize: 24,
margin: 0,
opacity: 0.8,
}}
>
{designation}
</p>
) : null}
{bio ? (
<p
style={{
fontSize: 22,
margin: 0,
opacity: 0.75,
maxWidth: 600,
lineHeight: 1.4,
}}
>
{bio.length > 120 ? bio.slice(0, 117) + "..." : bio}
</p>
) : null}
</div>
</div>
{/* Footer */}
<div
style={{
display: "flex",
justifyContent: "flex-end",
padding: 30,
}}
>
{/* Logo */}
<div style={{ display: "flex", gap: 10, alignItems: "center" }}>
<img
style={{ height: 48 }}
src={(await getFileLocation("logo-lg.png")) as any}
alt="logo"
/>
<p style={{ fontSize: 28 }}>TechDiary</p>
</div>
</div>
</div>
),
{
...size,
fonts: [
{
name: "BANGLA_FONT",
data: await getFileLocation("fonts/HindSiliguri-Regular.ttf"),
style: "normal",
weight: 400,
},
],
}
);
}