2024-03-09 22:50:55 -06:00
|
|
|
import { readFileSync } from 'fs';
|
2024-03-09 22:39:04 -06:00
|
|
|
import satori from 'satori';
|
2024-03-13 18:15:13 -05:00
|
|
|
import robotoBlack from './Roboto-Black.ttf';
|
|
|
|
|
import robotoBold from './Roboto-Bold.ttf';
|
|
|
|
|
import roboto from './Roboto.ttf';
|
2024-03-09 22:39:04 -06:00
|
|
|
|
|
|
|
|
const fonts = [
|
2024-03-13 18:15:13 -05:00
|
|
|
{ file: roboto, weight: 400 as const },
|
|
|
|
|
{ file: robotoBold, weight: 700 as const },
|
|
|
|
|
{ file: robotoBlack, weight: 900 as const },
|
2024-03-09 22:39:04 -06:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
}
|