og/lib/render.js

14 lines
454 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'
2023-09-10 14:48:50 -04:00
const style = fs.readFileSync('./assets/style.css', 'utf8')
2023-08-02 18:37:47 -04:00
2023-08-03 10:49:25 -04:00
export default async function (html, options = {}) {
2023-09-10 14:48:50 -04:00
return html2png(`<style>${style}</style>${html}`, options)
2023-08-02 18:37:47 -04:00
}
2023-08-02 19:54:54 -04:00
export async function renderHtml(html) {
2023-09-10 14:48:50 -04:00
const styleNow = await fs.promises.readFile('./assets/style.css', 'utf8')
return await htmlParser(`<style>${styleNow}</style>${html}`)
2023-08-02 19:54:54 -04:00
}