43 lines
910 B
JavaScript
43 lines
910 B
JavaScript
import html2png, { renderHtml as htmlParser } from '@besties/html2png'
|
|
import fs from 'node:fs'
|
|
|
|
const figtreeRegular = fs.readFileSync('./assets/Figtree-Regular.woff')
|
|
const figtreeMedium = fs.readFileSync('./assets/Figtree-Medium.woff')
|
|
const figtreeExtraBold = fs.readFileSync('./assets/Figtree-ExtraBold.woff')
|
|
|
|
const css = fs.readFileSync('./assets/style.css', 'utf8')
|
|
|
|
const renderOptions = {
|
|
fonts: [
|
|
{
|
|
name: 'Figtree',
|
|
data: figtreeRegular,
|
|
weight: 400,
|
|
style: 'normal'
|
|
},
|
|
{
|
|
name: 'Figtree',
|
|
data: figtreeMedium,
|
|
weight: 500,
|
|
style: 'normal'
|
|
},
|
|
{
|
|
name: 'Figtree',
|
|
data: figtreeExtraBold,
|
|
weight: 800,
|
|
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
|
|
}
|