feat: core chunk 7

This commit is contained in:
TrèsAbhi committed 2023-10-14 11:36:10 -05:00
1 parent d726005c38
commit 01dd7ad9c6
39 files changed
+83 -87

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import { readFile } from 'fs';
import { join } from 'path';
import satori from 'satori';
import robotoBlackFile from '../../assets/fonts/Roboto-Black.ttf';
import robotoBoldFile from '../../assets/fonts/Roboto-Bold.ttf';
import robotoFile from '../../assets/fonts/Roboto.ttf';
const FONT_NAME = 'Roboto';
const FONT_FILES = [robotoFile, robotoBoldFile, robotoBlackFile];
let roboto: Buffer;
let robotoBold: Buffer;
let robotoBlack: Buffer;
console.log('Importing fonts...');
Promise.all(
FONT_FILES.map(
(file) =>
new Promise<Buffer>((resolve, reject) => {
const path = join(__dirname, file);
readFile(path, (error, data) => {
if (error) reject(error);
resolve(data);
});
}),
),
).then((data) => {
[roboto, robotoBold, robotoBlack] = data;
console.log('Fonts imported');
});
export default async function jsxToSvg(jsx: JSX.Element) {
return await satori(jsx, {
width: 480,
fonts: [
{ data: roboto, name: FONT_NAME, weight: 400 },
{ data: robotoBold, name: FONT_NAME, weight: 700 },
{ data: robotoBlack, name: FONT_NAME, weight: 900 },
],
});
}