og/lib/render.js

43 lines
910 B
JavaScript
Raw Normal View History

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 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'
}
]
}
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
}