|
| 1 | +import { ImageResponse } from 'next/og' |
| 2 | + |
| 3 | +/** |
| 4 | + * On-demand Open Graph image generator. Renders a 1200x630 branded social card |
| 5 | + * with the page title and section, so every shared link gets a unique preview. |
| 6 | + * Called via lib/og.ts `ogImageUrl()` from page metadata; CDN-cached by URL. |
| 7 | + */ |
| 8 | +export const runtime = 'nodejs' |
| 9 | + |
| 10 | +const TYPE_LABELS: Record<string, string> = { |
| 11 | + docs: 'Documentation', |
| 12 | + blog: 'Blog', |
| 13 | + changelog: 'Changelog', |
| 14 | +} |
| 15 | + |
| 16 | +export function GET(request: Request) { |
| 17 | + const { searchParams } = new URL(request.url) |
| 18 | + const rawTitle = searchParams.get('title')?.trim() |
| 19 | + const title = (rawTitle && rawTitle.length > 0 ? rawTitle : 'The Open-Source AI Platform').slice( |
| 20 | + 0, |
| 21 | + 110, |
| 22 | + ) |
| 23 | + const type = searchParams.get('type') ?? '' |
| 24 | + const label = TYPE_LABELS[type] ?? 'librechat.ai' |
| 25 | + // Scale the title down for longer headlines so they stay on the card. |
| 26 | + const fontSize = title.length > 70 ? 56 : title.length > 40 ? 68 : 80 |
| 27 | + |
| 28 | + return new ImageResponse( |
| 29 | + <div |
| 30 | + style={{ |
| 31 | + width: '100%', |
| 32 | + height: '100%', |
| 33 | + display: 'flex', |
| 34 | + flexDirection: 'column', |
| 35 | + justifyContent: 'space-between', |
| 36 | + padding: '80px', |
| 37 | + backgroundColor: '#0a0a0a', |
| 38 | + backgroundImage: |
| 39 | + 'radial-gradient(circle at 18% 0%, rgba(99,102,241,0.22), transparent 45%), radial-gradient(circle at 100% 100%, rgba(56,189,248,0.16), transparent 45%)', |
| 40 | + color: '#fafafa', |
| 41 | + fontFamily: 'sans-serif', |
| 42 | + }} |
| 43 | + > |
| 44 | + {/* Brand */} |
| 45 | + <div style={{ display: 'flex', alignItems: 'center', gap: '20px' }}> |
| 46 | + <div |
| 47 | + style={{ |
| 48 | + display: 'flex', |
| 49 | + alignItems: 'center', |
| 50 | + justifyContent: 'center', |
| 51 | + width: '64px', |
| 52 | + height: '64px', |
| 53 | + borderRadius: '16px', |
| 54 | + background: 'linear-gradient(135deg, #6366f1, #38bdf8)', |
| 55 | + fontSize: '40px', |
| 56 | + }} |
| 57 | + > |
| 58 | + 🪶 |
| 59 | + </div> |
| 60 | + <div style={{ fontSize: '34px', fontWeight: 700, letterSpacing: '-0.02em' }}>LibreChat</div> |
| 61 | + </div> |
| 62 | + |
| 63 | + {/* Title */} |
| 64 | + <div |
| 65 | + style={{ |
| 66 | + display: 'flex', |
| 67 | + fontSize, |
| 68 | + fontWeight: 700, |
| 69 | + lineHeight: 1.1, |
| 70 | + letterSpacing: '-0.03em', |
| 71 | + maxWidth: '1000px', |
| 72 | + }} |
| 73 | + > |
| 74 | + {title} |
| 75 | + </div> |
| 76 | + |
| 77 | + {/* Footer */} |
| 78 | + <div |
| 79 | + style={{ |
| 80 | + display: 'flex', |
| 81 | + alignItems: 'center', |
| 82 | + justifyContent: 'space-between', |
| 83 | + fontSize: '26px', |
| 84 | + color: '#a1a1aa', |
| 85 | + }} |
| 86 | + > |
| 87 | + <div |
| 88 | + style={{ |
| 89 | + display: 'flex', |
| 90 | + textTransform: 'uppercase', |
| 91 | + letterSpacing: '0.12em', |
| 92 | + fontWeight: 600, |
| 93 | + }} |
| 94 | + > |
| 95 | + {label} |
| 96 | + </div> |
| 97 | + <div style={{ display: 'flex' }}>www.librechat.ai</div> |
| 98 | + </div> |
| 99 | + </div>, |
| 100 | + { width: 1200, height: 630 }, |
| 101 | + ) |
| 102 | +} |
0 commit comments