mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: fast font loading
This commit is contained in:
1 parent
3f83fffade
commit
377a00aaf1
1 file changed
+8
-11
@@ -1,26 +1,23 @@
|
|||||||
import { readFileSync } from 'fs';
|
import { readFile } from 'fs/promises';
|
||||||
import satori from 'satori';
|
import satori from 'satori';
|
||||||
import { RenderConfiguration } from '../renderConfiguration';
|
import { RenderConfiguration } from '../renderConfiguration';
|
||||||
import robotoBlack from './Roboto-Black.ttf';
|
import robotoBlack from './Roboto-Black.ttf';
|
||||||
import robotoBold from './Roboto-Bold.ttf';
|
import robotoBold from './Roboto-Bold.ttf';
|
||||||
import roboto from './Roboto.ttf';
|
import roboto from './Roboto.ttf';
|
||||||
|
|
||||||
const fonts = [
|
const fontsPromise = [
|
||||||
{ file: roboto, weight: 400 as const },
|
{ file: roboto, weight: 400 as const },
|
||||||
{ file: robotoBold, weight: 700 as const },
|
{ file: robotoBold, weight: 700 as const },
|
||||||
{ file: robotoBlack, weight: 900 as const },
|
{ file: robotoBlack, weight: 900 as const },
|
||||||
];
|
].map(async ({ file, weight }) => {
|
||||||
|
const data = await readFile(`dist/bot/workers/${file}`);
|
||||||
|
return { name: 'Roboto', weight, data };
|
||||||
|
});
|
||||||
|
|
||||||
export default async function jsxToSvg(
|
export default async function jsxToSvg(
|
||||||
jsx: JSX.Element,
|
jsx: JSX.Element,
|
||||||
renderConfiguration = new RenderConfiguration(),
|
renderConfiguration = new RenderConfiguration(),
|
||||||
) {
|
) {
|
||||||
return await satori(jsx, {
|
const fonts = await Promise.all(fontsPromise);
|
||||||
width: renderConfiguration.width,
|
return await satori(jsx, { width: renderConfiguration.width, fonts });
|
||||||
fonts: fonts.map(({ file, weight }) => ({
|
|
||||||
weight,
|
|
||||||
name: 'Roboto',
|
|
||||||
data: readFileSync(`${__dirname}/${file}`),
|
|
||||||
})),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user