-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen-svg.mts
49 lines (46 loc) · 1.54 KB
/
gen-svg.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { fileURLToPath } from 'node:url'
import { readFile, writeFile } from 'node:fs/promises'
import { dirname, resolve } from 'node:path'
import { exit } from 'node:process'
import { type SatoriOptions, satoriAstro } from 'x-satori/astro'
(async function () {
const _DIRNAME = typeof __dirname !== 'undefined'
? __dirname
: dirname(fileURLToPath(import.meta.url))
const _OUTPUT = resolve(_DIRNAME, './image/og.svg')
const opt: SatoriOptions = {
height: 628,
width: 1200,
fonts: [
{
name: 'Inter',
data: await readFile(resolve(_DIRNAME, './fonts/Inter-Medium.woff')),
weight: 400,
style: 'normal',
},
{
name: 'Inter',
data: await readFile(resolve(_DIRNAME, './fonts/Inter-Bold.woff')),
weight: 700,
style: 'normal',
},
{
name: 'Noto Sans Symbols',
data: await readFile(resolve(_DIRNAME, './fonts/NotoSansSymbols2-Regular.ttf')),
weight: 700,
style: 'normal',
},
],
props: {
title: 'hello world',
desc: 'examples',
site: 'https://qbb.sh',
},
}
const templateStr = await readFile(resolve(_DIRNAME, './Template.astro'), 'utf8')
const strSVG = await satoriAstro(opt, templateStr)
await writeFile(_OUTPUT, strSVG)
}()).catch((err: Error) => {
console.error(err)
exit(1)
})