Skip to content

Commit 75a5b43

Browse files
authored
feat(og): update og image (#2362)
1 parent 8d0e50f commit 75a5b43

File tree

2 files changed

+50
-22
lines changed

2 files changed

+50
-22
lines changed

apps/docs/app/[lang]/[[...slug]]/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ export async function generateMetadata(props: {
243243
const baseUrl = 'https://docs.sim.ai'
244244
const fullUrl = `${baseUrl}${page.url}`
245245

246-
const ogImageUrl = `${baseUrl}/api/og?title=${encodeURIComponent(page.data.title)}&category=DOCUMENTATION`
246+
const description = page.data.description || ''
247+
const ogImageUrl = `${baseUrl}/api/og?title=${encodeURIComponent(page.data.title)}&category=DOCUMENTATION${description ? `&description=${encodeURIComponent(description)}` : ''}`
247248

248249
return {
249250
title: page.data.title,

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

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function getTitleFontSize(title: string): number {
1818
/**
1919
* Loads a Google Font dynamically by fetching the CSS and extracting the font URL.
2020
*/
21-
async function loadGoogleFont(font: string, text: string): Promise<ArrayBuffer> {
22-
const url = `https://fonts.googleapis.com/css2?family=${font}:wght@500;600&text=${encodeURIComponent(text)}`
21+
async function loadGoogleFont(font: string, weights: string, text: string): Promise<ArrayBuffer> {
22+
const url = `https://fonts.googleapis.com/css2?family=${font}:wght@${weights}&text=${encodeURIComponent(text)}`
2323
const css = await (await fetch(url)).text()
2424
const resource = css.match(/src: url\((.+)\) format\('(opentype|truetype)'\)/)
2525

@@ -40,13 +40,13 @@ export async function GET(request: NextRequest) {
4040
const { searchParams } = new URL(request.url)
4141
const title = searchParams.get('title') || 'Documentation'
4242
const category = searchParams.get('category') || 'DOCUMENTATION'
43+
const description = searchParams.get('description') || ''
4344

4445
const baseUrl = new URL(request.url).origin
4546
const backgroundImageUrl = `${baseUrl}/static/og-background.png`
4647

47-
// Load Inter font dynamically from Google Fonts
48-
const allText = `${title}${category}docs.sim.ai`
49-
const fontData = await loadGoogleFont('Inter', allText)
48+
const allText = `${title}${category}${description}docs.sim.ai`
49+
const fontData = await loadGoogleFont('Geist', '400;500;600', allText)
5050

5151
return new ImageResponse(
5252
<div
@@ -55,9 +55,9 @@ export async function GET(request: NextRequest) {
5555
width: '100%',
5656
display: 'flex',
5757
flexDirection: 'column',
58-
backgroundColor: '#121212',
58+
background: 'linear-gradient(315deg, #1e1e3f 0%, #1a1a2e 40%, #0f0f0f 100%)',
5959
position: 'relative',
60-
fontFamily: 'Inter',
60+
fontFamily: 'Geist',
6161
}}
6262
>
6363
{/* Background texture */}
@@ -71,7 +71,21 @@ export async function GET(request: NextRequest) {
7171
width: '100%',
7272
height: '100%',
7373
objectFit: 'cover',
74-
opacity: 0.06,
74+
opacity: 0.04,
75+
}}
76+
/>
77+
78+
{/* Subtle purple glow from bottom right */}
79+
<div
80+
style={{
81+
position: 'absolute',
82+
bottom: 0,
83+
right: 0,
84+
width: '50%',
85+
height: '100%',
86+
background:
87+
'radial-gradient(ellipse at bottom right, rgba(112, 31, 252, 0.1) 0%, transparent 50%)',
88+
display: 'flex',
7589
}}
7690
/>
7791

@@ -80,28 +94,28 @@ export async function GET(request: NextRequest) {
8094
style={{
8195
display: 'flex',
8296
flexDirection: 'column',
83-
padding: '60px 72px',
97+
padding: '56px 72px',
8498
height: '100%',
8599
justifyContent: 'space-between',
86100
}}
87101
>
88102
{/* Logo */}
89-
<img src={`${baseUrl}/static/logo.png`} alt='sim' height={36} />
103+
<img src={`${baseUrl}/static/logo.png`} alt='sim' height={32} />
90104

91-
{/* Category + Title */}
105+
{/* Category + Title + Description */}
92106
<div
93107
style={{
94108
display: 'flex',
95109
flexDirection: 'column',
96-
gap: 16,
110+
gap: 12,
97111
}}
98112
>
99113
<span
100114
style={{
101-
fontSize: 14,
102-
fontWeight: 500,
103-
color: '#737373',
104-
letterSpacing: '0.08em',
115+
fontSize: 15,
116+
fontWeight: 600,
117+
color: '#802fff',
118+
letterSpacing: '0.02em',
105119
}}
106120
>
107121
{category}
@@ -111,20 +125,33 @@ export async function GET(request: NextRequest) {
111125
fontSize: getTitleFontSize(title),
112126
fontWeight: 600,
113127
color: '#ffffff',
114-
lineHeight: 1.15,
128+
lineHeight: 1.1,
115129
letterSpacing: '-0.02em',
116130
}}
117131
>
118132
{title}
119133
</span>
134+
{description && (
135+
<span
136+
style={{
137+
fontSize: 18,
138+
fontWeight: 400,
139+
color: '#a1a1aa',
140+
lineHeight: 1.4,
141+
marginTop: 4,
142+
}}
143+
>
144+
{description.length > 100 ? `${description.slice(0, 100)}...` : description}
145+
</span>
146+
)}
120147
</div>
121148

122149
{/* Footer */}
123150
<span
124151
style={{
125-
fontSize: 16,
126-
fontWeight: 400,
127-
color: '#525252',
152+
fontSize: 15,
153+
fontWeight: 500,
154+
color: '#52525b',
128155
}}
129156
>
130157
docs.sim.ai
@@ -136,7 +163,7 @@ export async function GET(request: NextRequest) {
136163
height: 630,
137164
fonts: [
138165
{
139-
name: 'Inter',
166+
name: 'Geist',
140167
data: fontData,
141168
style: 'normal',
142169
},

0 commit comments

Comments
 (0)