1+ import type { CSSProperties } from 'react'
12import { ImageResponse } from 'next/og'
23import type { NextRequest } from 'next/server'
34
@@ -9,13 +10,47 @@ const TITLE_FONT_SIZE = {
910 small : 48 ,
1011} as const
1112const FONT_CACHE_REVALIDATE_SECONDS = 60 * 60 * 24 * 30
13+ const OG_CONTAINER_STYLE = {
14+ height : '100%' ,
15+ width : '100%' ,
16+ display : 'flex' ,
17+ flexDirection : 'column' ,
18+ justifyContent : 'space-between' ,
19+ padding : '56px 64px' ,
20+ background : '#121212' ,
21+ fontFamily : 'Geist' ,
22+ } satisfies CSSProperties
23+ const OG_TITLE_STYLE = {
24+ fontWeight : 500 ,
25+ color : '#fafafa' ,
26+ lineHeight : 1.2 ,
27+ letterSpacing : '-0.02em' ,
28+ } satisfies CSSProperties
29+ const OG_FOOTER_STYLE = {
30+ display : 'flex' ,
31+ justifyContent : 'space-between' ,
32+ alignItems : 'center' ,
33+ width : '100%' ,
34+ } satisfies CSSProperties
35+ const OG_DOMAIN_STYLE = {
36+ fontSize : 20 ,
37+ fontWeight : 400 ,
38+ color : '#71717a' ,
39+ } satisfies CSSProperties
1240
1341function getTitleFontSize ( title : string ) : number {
1442 if ( title . length > 45 ) return TITLE_FONT_SIZE . small
1543 if ( title . length > 30 ) return TITLE_FONT_SIZE . medium
1644 return TITLE_FONT_SIZE . large
1745}
1846
47+ function getTitleStyle ( title : string ) : CSSProperties {
48+ return {
49+ ...OG_TITLE_STYLE ,
50+ fontSize : getTitleFontSize ( title ) ,
51+ }
52+ }
53+
1954/**
2055 * Loads a Google Font dynamically by fetching the CSS and extracting the font URL.
2156 */
@@ -83,50 +118,14 @@ export async function GET(request: NextRequest) {
83118 const fontData = await loadGoogleFont ( 'Geist' , '400;500;600' , allText )
84119
85120 return new ImageResponse (
86- < div
87- style = { {
88- height : '100%' ,
89- width : '100%' ,
90- display : 'flex' ,
91- flexDirection : 'column' ,
92- justifyContent : 'space-between' ,
93- padding : '56px 64px' ,
94- background : '#121212' , // Dark mode background matching docs (hsla 0, 0%, 7%)
95- fontFamily : 'Geist' ,
96- } }
97- >
121+ < div style = { OG_CONTAINER_STYLE } >
98122 { /* Title at top */ }
99- < span
100- style = { {
101- fontSize : getTitleFontSize ( title ) ,
102- fontWeight : 500 ,
103- color : '#fafafa' , // Light text matching docs
104- lineHeight : 1.2 ,
105- letterSpacing : '-0.02em' ,
106- } }
107- >
108- { title }
109- </ span >
123+ < span style = { getTitleStyle ( title ) } > { title } </ span >
110124
111125 { /* Footer: icon left, domain right */ }
112- < div
113- style = { {
114- display : 'flex' ,
115- justifyContent : 'space-between' ,
116- alignItems : 'center' ,
117- width : '100%' ,
118- } }
119- >
126+ < div style = { OG_FOOTER_STYLE } >
120127 < SimLogoFull />
121- < span
122- style = { {
123- fontSize : 20 ,
124- fontWeight : 400 ,
125- color : '#71717a' ,
126- } }
127- >
128- docs.sim.ai
129- </ span >
128+ < span style = { OG_DOMAIN_STYLE } > docs.sim.ai</ span >
130129 </ div >
131130 </ div > ,
132131 {
0 commit comments