og/lib/render.js
2023-12-21 06:47:27 -06:00

36 lines
852 B
JavaScript

import html2png, { renderHTML as inline } from '@besties/html2png'
import fs from 'node:fs'
const style = fs.readFileSync('./assets/style.css', 'utf8')
export default async function (html, options = {}) {
return html2png(`<style>${style}</style>${html}`, options)
}
export async function renderHtml(html) {
const styleNow = await fs.promises.readFile('./assets/style.css', 'utf8')
return (
`<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
:root {
height: 100%;
font-family: 'DM Sans', Arial, Helvetica, sans-serif;
}
* {
font-family: inherit;
}
body {
margin: 0;
background-color: black;
display: grid;
place-items: center;
height: 100%;
}
</style>
<title>OpenGraph Debug Preview</title>
</head>` + (await inline(`<style>${styleNow}</style>${html}`))
)
}