og/lib/render.js

21 lines
495 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-08-03 15:27:34 -04:00
import { DMSans } from './fonts.js'
2023-08-02 18:37:47 -04:00
const css = fs.readFileSync('./assets/style.css', 'utf8')
const renderOptions = {
2023-08-03 15:27:34 -04:00
fonts: DMSans
2023-08-02 18:37:47 -04:00
}
2023-08-03 10:49:25 -04:00
export default async function (html, options = {}) {
return html2png(html, css, { ...renderOptions, ...options })
2023-08-02 18:37:47 -04:00
}
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
}