|
| 1 | +import { ImageResponse } from "next/og"; |
| 2 | + |
| 3 | +export const runtime = "edge"; |
| 4 | + |
| 5 | +const OG_WIDTH = 1200; |
| 6 | +const OG_HEIGHT = 630; |
| 7 | +const DEFAULT_TITLE = "Claws.supply"; |
| 8 | +const DEFAULT_DESCRIPTION = "OpenClaw AI agent template marketplace."; |
| 9 | + |
| 10 | +function truncateText(value: string, maxLength: number) { |
| 11 | + const normalized = value.trim(); |
| 12 | + |
| 13 | + if (normalized.length <= maxLength) { |
| 14 | + return normalized; |
| 15 | + } |
| 16 | + |
| 17 | + return `${normalized.slice(0, Math.max(maxLength - 1, 1)).trimEnd()}…`; |
| 18 | +} |
| 19 | + |
| 20 | +export function GET(request: Request) { |
| 21 | + const { searchParams } = new URL(request.url); |
| 22 | + const title = truncateText(searchParams.get("title") ?? DEFAULT_TITLE, 110); |
| 23 | + const description = truncateText( |
| 24 | + searchParams.get("description") ?? DEFAULT_DESCRIPTION, |
| 25 | + 180, |
| 26 | + ); |
| 27 | + |
| 28 | + return new ImageResponse( |
| 29 | + ( |
| 30 | + <div |
| 31 | + style={{ |
| 32 | + display: "flex", |
| 33 | + width: "100%", |
| 34 | + height: "100%", |
| 35 | + background: "linear-gradient(135deg, #070707 0%, #121212 60%, #1e1e1e 100%)", |
| 36 | + color: "#f5f5f5", |
| 37 | + position: "relative", |
| 38 | + fontFamily: "ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif", |
| 39 | + }} |
| 40 | + > |
| 41 | + <div |
| 42 | + style={{ |
| 43 | + position: "absolute", |
| 44 | + inset: 0, |
| 45 | + backgroundImage: |
| 46 | + "linear-gradient(to right, rgba(255,255,255,0.08) 1px, transparent 1px), linear-gradient(to bottom, rgba(255,255,255,0.08) 1px, transparent 1px)", |
| 47 | + backgroundSize: "120px 120px", |
| 48 | + opacity: 0.25, |
| 49 | + }} |
| 50 | + /> |
| 51 | + <div |
| 52 | + style={{ |
| 53 | + display: "flex", |
| 54 | + flexDirection: "column", |
| 55 | + justifyContent: "space-between", |
| 56 | + width: "100%", |
| 57 | + padding: "56px 64px", |
| 58 | + position: "relative", |
| 59 | + }} |
| 60 | + > |
| 61 | + <div |
| 62 | + style={{ |
| 63 | + fontSize: 26, |
| 64 | + letterSpacing: "0.18em", |
| 65 | + textTransform: "uppercase", |
| 66 | + color: "#f97316", |
| 67 | + fontWeight: 700, |
| 68 | + }} |
| 69 | + > |
| 70 | + claws.supply |
| 71 | + </div> |
| 72 | + <div style={{ display: "flex", flexDirection: "column", gap: 18, maxWidth: 980 }}> |
| 73 | + <div |
| 74 | + style={{ |
| 75 | + fontSize: title.length > 60 ? 58 : 70, |
| 76 | + lineHeight: 1.08, |
| 77 | + fontWeight: 700, |
| 78 | + letterSpacing: "-0.02em", |
| 79 | + }} |
| 80 | + > |
| 81 | + {title} |
| 82 | + </div> |
| 83 | + <div |
| 84 | + style={{ |
| 85 | + fontSize: 34, |
| 86 | + lineHeight: 1.25, |
| 87 | + color: "#d4d4d8", |
| 88 | + letterSpacing: "-0.01em", |
| 89 | + }} |
| 90 | + > |
| 91 | + {description} |
| 92 | + </div> |
| 93 | + </div> |
| 94 | + </div> |
| 95 | + </div> |
| 96 | + ), |
| 97 | + { |
| 98 | + width: OG_WIDTH, |
| 99 | + height: OG_HEIGHT, |
| 100 | + }, |
| 101 | + ); |
| 102 | +} |
0 commit comments