生成 OG 图片
使用 Deno 和 Supabase Edge Functions 生成 Open Graph 图片。在 GitHub 上查看。
🌐 Generate Open Graph images with Deno and Supabase Edge Functions. View on GitHub.
代码 #
🌐 Code
创建一个 handler.tsx 文件来在 React 中构建 OG 图片:
🌐 Create a handler.tsx file to construct the OG image in React:
import { ImageResponse } from 'npm:@vercel/og@^0'import React from 'npm:react@^19'export default function handler(req: Request) { return new ImageResponse( <div style={{ width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 128, background: 'lavender', }} > Hello OG Image! </div> )}创建一个 index.ts 文件来处理传入请求:
🌐 Create an index.ts file to execute the handler on incoming requests:
import { withSupabase } from 'npm:@supabase/server@^1'import handler from './handler.tsx'console.log('Hello from og-image Function!')// Public image endpoint, so deploy with --no-verify-jwt.export default { fetch: withSupabase({ auth: 'none' }, handler) }