import React from 'https://esm.sh/react@18.2.0'; // eslint-disable-next-line import/extensions import { ImageResponse } from 'https://deno.land/x/og_edge/mod.ts'; const MAX_AUTHORS = 5; export default async function handler(req: Request) { const params = new URL(req.url).searchParams; const title = params.get('title'); const authors = params.get('authors'); const product = params.get('product'); const description = params.get('description'); const parsedAuthors = authors && authors .split(',') .map((author) => { const [name, github] = author.split('@'); return { name: name.trim(), github: github.trim() }; }) .filter(({ name, github }) => name && github); const withAuthors = parsedAuthors && parsedAuthors.length > 0; let starCount = 0; return new ImageResponse( (

{product}

{title && title.split('\\n').map((line) => (

{line.split('*').flatMap((text, index) => { if (index > 0) { starCount += 1; } const isBlue = starCount % 2 === 1; return text.split(' ').map((word) => ( 0 ? 15 : 0, }} > {word} )); })}

))} {description && (

{description}

)}
{withAuthors && parsedAuthors.slice(0, MAX_AUTHORS).map(({ name, github }) => { return (
{name} @{github}
); })}
), { width: 1280, height: 640, // debug: true, fonts: [ { name: 'IBM Plex Sans', data: await fetch('https://fonts.cdnfonts.com/s/15449/IBMPlexSans-Medium.woff').then( (a) => a.arrayBuffer(), ), weight: 500, style: 'normal', }, { name: 'General Sans', data: await fetch('https://fonts.cdnfonts.com/s/85793/GeneralSans-Semibold.woff').then( (a) => a.arrayBuffer(), ), weight: 600, style: 'normal', }, { name: 'General Sans', data: await fetch('https://fonts.cdnfonts.com/s/85793/GeneralSans-Bold.woff').then((a) => a.arrayBuffer(), ), weight: 700, style: 'normal', }, ], // Manage the caching headers: { // Cache control is already done by the package (https://github.com/ascorbic/og-edge/blob/d533ef878801d7f808eb004f254e782ec6ba1e3c/mod.ts#L233-L240) 'Netlify-Vary': 'query', }, }, ); } export const config = { cache: 'manual', path: '/edge-functions/og-image', };