|
| 1 | +// TODO: Restore dynamic satori-based OG image generation once Cloudflare compatibility is resolved. |
| 2 | +// Blocked by: satori and @resvg/resvg-js not being compatible with Cloudflare Workers. |
| 3 | +// Consider switching to @vercel/og which handles Wasm initialization for edge runtimes. |
| 4 | +// |
| 5 | +// import { render } from 'svelte/server'; |
| 6 | +// import satori from 'satori'; |
| 7 | +// import { html } from 'satori-html'; |
| 8 | +// import { Resvg } from '@resvg/resvg-js'; |
| 9 | +// |
| 10 | +// import InterRegular from '@fontsource/inter/files/inter-latin-400-normal.woff'; |
| 11 | +// import InterSemibold from '@fontsource/inter/files/inter-latin-600-normal.woff'; |
| 12 | +// import InterBold from '@fontsource/inter/files/inter-latin-700-normal.woff'; |
| 13 | +// |
| 14 | +// import { dev } from '$app/environment'; |
| 15 | +// import { read } from '$app/server'; |
| 16 | +// import type { RequestHandler } from './$types'; |
| 17 | +// |
| 18 | +// import Thumbnail from './Thumbnail.svelte'; |
| 19 | +// |
| 20 | +// const interRegular = read(InterRegular).arrayBuffer(); |
| 21 | +// const interSemibold = read(InterSemibold).arrayBuffer(); |
| 22 | +// const interBold = read(InterBold).arrayBuffer(); |
| 23 | +// |
| 24 | +// export const GET: RequestHandler = async ({ url }) => { |
| 25 | +// const renderedComponent = render(Thumbnail, { |
| 26 | +// props: { |
| 27 | +// title: url.searchParams.get('title') ?? '', |
| 28 | +// description: url.searchParams.get('description') ?? undefined, |
| 29 | +// component: url.searchParams.get('component') ?? undefined |
| 30 | +// } |
| 31 | +// }); |
| 32 | +// |
| 33 | +// const markup = html(`<style>${renderedComponent.head}</style>${renderedComponent.body}`); |
| 34 | +// |
| 35 | +// const svg = await satori(markup, { |
| 36 | +// width: 1200, |
| 37 | +// height: 630, |
| 38 | +// fonts: [ |
| 39 | +// { |
| 40 | +// name: 'Inter', |
| 41 | +// data: await interRegular, |
| 42 | +// weight: 400, |
| 43 | +// style: 'normal' |
| 44 | +// }, |
| 45 | +// { |
| 46 | +// name: 'Inter', |
| 47 | +// data: await interSemibold, |
| 48 | +// weight: 600, |
| 49 | +// style: 'normal' |
| 50 | +// }, |
| 51 | +// { |
| 52 | +// name: 'Inter', |
| 53 | +// data: await interBold, |
| 54 | +// weight: 700, |
| 55 | +// style: 'normal' |
| 56 | +// } |
| 57 | +// ] |
| 58 | +// }); |
| 59 | +// |
| 60 | +// const png = new Resvg(svg, { |
| 61 | +// fitTo: { |
| 62 | +// mode: 'original' |
| 63 | +// } |
| 64 | +// }) |
| 65 | +// .render() |
| 66 | +// .asPng(); |
| 67 | +// |
| 68 | +// const response = new Response(new Uint8Array(png), { |
| 69 | +// headers: { |
| 70 | +// 'Content-Type': 'image/png' |
| 71 | +// } |
| 72 | +// }); |
| 73 | +// if (!dev) response.headers.append('Cache-Control', `max-age=${60 * 60 * 24 * 30}, immutable`); |
| 74 | +// return response; |
| 75 | +// }; |
0 commit comments