2023-08-02 19:54:54 -04:00
|
|
|
import html2png, { renderHtml as htmlParser } from '@besties/html2png'
|
2023-08-02 18:37:47 -04:00
|
|
|
import fs from 'node:fs'
|
|
|
|
|
|
|
|
const css = fs.readFileSync('./assets/style.css', 'utf8')
|
|
|
|
|
|
|
|
const renderOptions = {
|
|
|
|
fonts: [
|
|
|
|
{
|
2023-08-02 23:26:13 -04:00
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-Thin.ttf'),
|
|
|
|
weight: 100,
|
|
|
|
style: 'normal'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-ThinItalic.ttf'),
|
|
|
|
weight: 100,
|
|
|
|
style: 'italic'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-ExtraLight.ttf'),
|
|
|
|
weight: 200,
|
|
|
|
style: 'normal'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-ExtraLightItalic.ttf'),
|
|
|
|
weight: 200,
|
|
|
|
style: 'italic'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-Light.ttf'),
|
|
|
|
weight: 300,
|
|
|
|
style: 'normal'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-LightItalic.ttf'),
|
|
|
|
weight: 300,
|
|
|
|
style: 'italic'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-Regular.ttf'),
|
2023-08-02 18:37:47 -04:00
|
|
|
weight: 400,
|
|
|
|
style: 'normal'
|
|
|
|
},
|
|
|
|
{
|
2023-08-02 23:26:13 -04:00
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-Italic.ttf'),
|
|
|
|
weight: 400,
|
|
|
|
style: 'italic'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-Medium.ttf'),
|
2023-08-02 18:37:47 -04:00
|
|
|
weight: 500,
|
|
|
|
style: 'normal'
|
|
|
|
},
|
|
|
|
{
|
2023-08-02 23:26:13 -04:00
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-MediumItalic.ttf'),
|
|
|
|
weight: 500,
|
|
|
|
style: 'italic'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-SemiBold.ttf'),
|
|
|
|
weight: 600,
|
|
|
|
style: 'normal'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-SemiBoldItalic.ttf'),
|
|
|
|
weight: 600,
|
|
|
|
style: 'italic'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-Bold.ttf'),
|
|
|
|
weight: 700,
|
|
|
|
style: 'normal'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-BoldItalic.ttf'),
|
|
|
|
weight: 700,
|
|
|
|
style: 'italic'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-ExtraBold.ttf'),
|
|
|
|
weight: 800,
|
|
|
|
style: 'normal'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-ExtraBoldItalic.ttf'),
|
2023-08-02 18:37:47 -04:00
|
|
|
weight: 800,
|
2023-08-02 23:26:13 -04:00
|
|
|
style: 'italic'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-Black.ttf'),
|
|
|
|
weight: 900,
|
|
|
|
style: 'normal'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'DM Sans',
|
|
|
|
data: fs.readFileSync('./assets/DMSans-BlackItalic.ttf'),
|
|
|
|
weight: 900,
|
2023-08-02 18:37:47 -04:00
|
|
|
style: 'normal'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2023-08-02 18:51:06 -04:00
|
|
|
export default async function (html) {
|
2023-08-02 18:37:47 -04:00
|
|
|
return html2png(html, css, renderOptions)
|
|
|
|
}
|
2023-08-02 19:54:54 -04:00
|
|
|
|
|
|
|
export async function renderHtml(html) {
|
|
|
|
return htmlParser(
|
|
|
|
html,
|
|
|
|
await fs.promises.readFile('./assets/style.css', 'utf8')
|
|
|
|
).outerHTML
|
|
|
|
}
|