129 lines
2.6 KiB
JavaScript
129 lines
2.6 KiB
JavaScript
import html2png, { renderHtml as htmlParser } from '@besties/html2png'
|
|
import fs from 'node:fs'
|
|
|
|
const css = fs.readFileSync('./assets/style.css', 'utf8')
|
|
|
|
const renderOptions = {
|
|
fonts: [
|
|
{
|
|
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'),
|
|
weight: 400,
|
|
style: 'normal'
|
|
},
|
|
{
|
|
name: 'DM Sans',
|
|
data: fs.readFileSync('./assets/DMSans-Italic.ttf'),
|
|
weight: 400,
|
|
style: 'italic'
|
|
},
|
|
{
|
|
name: 'DM Sans',
|
|
data: fs.readFileSync('./assets/DMSans-Medium.ttf'),
|
|
weight: 500,
|
|
style: 'normal'
|
|
},
|
|
{
|
|
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'),
|
|
weight: 800,
|
|
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,
|
|
style: 'normal'
|
|
}
|
|
]
|
|
}
|
|
|
|
export default async function (html) {
|
|
return html2png(html, css, renderOptions)
|
|
}
|
|
|
|
export async function renderHtml(html) {
|
|
return htmlParser(
|
|
html,
|
|
await fs.promises.readFile('./assets/style.css', 'utf8')
|
|
).outerHTML
|
|
}
|