Files
blitzkit/src/core/blitzkrieg/jsxToSvg/index.ts
T

30 lines
640 B
TypeScript
Raw Normal View History

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,
name: 'Roboto',
},
{
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,
name: 'Roboto-Bold',
},
{
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,
name: 'Roboto-Black',
},
];
export default async function jsxToSvg(jsx: JSX.Element) {
return await satori(jsx, {
width: 480,
2024-03-09 23:04:09 -06:00
fonts: fonts.map(({ file, ...font }) => ({
data: readFileSync(`${__dirname}/${file}`),
...font,
})),
2024-03-09 22:39:04 -06:00
});
}