2024-03-09 22:50:55 -06:00
|
|
|
import { readFileSync } from 'fs';
|
2024-03-09 22:39:04 -06:00
|
|
|
import satori from 'satori';
|
|
|
|
|
|
|
|
|
|
const fonts = [
|
|
|
|
|
{
|
2024-03-09 23:04:09 -06:00
|
|
|
file: require('./Roboto.ttf') as string,
|
2024-03-09 22:39:04 -06:00
|
|
|
weight: 400 as const,
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-03-09 23:04:09 -06:00
|
|
|
file: require('./Roboto-Bold.ttf') as string,
|
2024-03-09 22:39:04 -06:00
|
|
|
weight: 700 as const,
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-03-09 23:04:09 -06:00
|
|
|
file: require('./Roboto-Black.ttf') as string,
|
2024-03-09 22:39:04 -06:00
|
|
|
weight: 900 as const,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export default async function jsxToSvg(jsx: JSX.Element) {
|
|
|
|
|
return await satori(jsx, {
|
|
|
|
|
width: 480,
|
2024-03-09 23:33:14 -06:00
|
|
|
fonts: fonts.map(({ file, weight }) => ({
|
|
|
|
|
weight,
|
|
|
|
|
name: 'Roboto',
|
2024-03-09 23:04:09 -06:00
|
|
|
data: readFileSync(`${__dirname}/${file}`),
|
|
|
|
|
})),
|
2024-03-09 22:39:04 -06:00
|
|
|
});
|
|
|
|
|
}
|