-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gen-png.mts
27 lines (24 loc) · 948 Bytes
/
gen-png.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { fileURLToPath } from 'node:url'
import { readFile, writeFile } from 'node:fs/promises'
import { dirname, resolve } from 'node:path'
import { renderAsync } from '@resvg/resvg-js'
import { satoriAstro } from 'x-satori/astro'
(async function () {
const _DIRNAME = typeof __dirname !== 'undefined'
? __dirname
: dirname(fileURLToPath(import.meta.url))
const _OUTPUT = resolve(_DIRNAME, './og.png')
const templateStr = await readFile(resolve(_DIRNAME, './Template.astro'), 'utf8')
const satoriConfig = (await import('./config')).default
const strSVG = await satoriAstro(satoriConfig, templateStr)
const render = await renderAsync(strSVG, {
fitTo: {
mode: 'width',
value: 1200,
},
})
return await writeFile(_OUTPUT, render.asPng())
}()).catch(async (err: Error) => {
console.error(err)
await import('node:process').then(({ exit }) => exit(1))
})