2023-12-21 07:47:27 -05:00
|
|
|
import html2png, { renderHTML as inline } 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')
|
2023-12-21 07:47:27 -05:00
|
|
|
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}`))
|
|
|
|
)
|
2023-08-02 19:54:54 -04:00
|
|
|
}
|