mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 03:07:04 +02:00
feat: satori and resvg for rendering
This commit is contained in:
1 parent
e48ea4c307
commit
c834f4f966
34 files changed
+670
-501
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import { Resvg } from '@resvg/resvg-js';
|
||||
import { readFileSync } from 'fs';
|
||||
import { ReactNode } from 'react';
|
||||
import satori from 'satori';
|
||||
|
||||
const robotoFlex = readFileSync('src/assets/fonts/Roboto.ttf');
|
||||
const robotoFlexBold = readFileSync('src/assets/fonts/Roboto-Bold.ttf');
|
||||
const robotoFlexBlack = readFileSync('src/assets/fonts/Roboto-Black.ttf');
|
||||
|
||||
export default async function render(element: ReactNode) {
|
||||
const svg = await satori(element, {
|
||||
width: 640,
|
||||
fonts: [
|
||||
{ data: robotoFlex, name: 'Roboto Flex', weight: 400 },
|
||||
{ data: robotoFlexBold, name: 'Roboto Flex', weight: 700 },
|
||||
{ data: robotoFlexBlack, name: 'Roboto Flex', weight: 900 },
|
||||
],
|
||||
});
|
||||
const png = new Resvg(svg).render().asPng();
|
||||
|
||||
return png;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import Root from '../../components/Root.js';
|
||||
import { browser } from '../../index.js';
|
||||
|
||||
export default async function screenshotHTML(children: string) {
|
||||
const page = await browser.newPage();
|
||||
await page.setViewportSize({ width: 640, height: 1 });
|
||||
await page.setContent(Root(children));
|
||||
const screenshot = await page
|
||||
.locator('#root')
|
||||
.screenshot({ omitBackground: true, scale: 'css' });
|
||||
await page.close();
|
||||
|
||||
return screenshot;
|
||||
}
|
||||
Reference in new issue
Block a user