Highly ambitious ATProtocol AppView service and sdks
at main 52 lines 1.4 kB view raw
1/// <reference lib="deno.ns" /> 2 3import { LandingOGImage } from "../src/og-images/LandingOGImage.tsx"; 4import { fromJsx } from "@takumi-rs/helpers/jsx"; 5import { Renderer } from "@takumi-rs/core"; 6 7export async function handleLandingOGImage(_req: Request): Promise<Response> { 8 try { 9 // Load the Inter Variable font 10 const fontPath = "./src/fonts/InterVariable.ttf"; 11 const fontBuffer = await Deno.readFile(fontPath); 12 13 const fonts = [ 14 { 15 name: "Inter", 16 data: fontBuffer, 17 style: "normal" as const, 18 weight: 400, 19 }, 20 ]; 21 22 const renderer = new Renderer({ 23 //@ts-ignore Takumi types are wrong for some reason 24 fonts, 25 }); 26 27 // Generate landing page OG image using Takumi 28 const node = await fromJsx(<LandingOGImage />); 29 30 // Render to PNG using Takumi 31 const pngBuffer = await renderer.render(node, { 32 width: 1200, 33 height: 630, 34 format: "png", 35 }); 36 37 return new Response(pngBuffer, { 38 headers: { 39 "Content-Type": "image/png", 40 "Cache-Control": "public, max-age=3600", 41 }, 42 }); 43 } catch (error) { 44 const errorMessage = error instanceof Error 45 ? error.message 46 : "Unknown error"; 47 console.error("Error generating OG image:", errorMessage, error); 48 return new Response(`Error generating image: ${errorMessage}`, { 49 status: 500, 50 }); 51 } 52}