This commit is contained in:
maropboia 2024-05-03 11:38:44 +06:00
parent e886f8dfbf
commit c7f6b4a0be

View file

@ -7,32 +7,23 @@ import { defineSatoriConfig } from 'x-satori/vue'
const __dirname = dirname(fileURLToPath(import.meta.url)) const __dirname = dirname(fileURLToPath(import.meta.url))
const __fonts = resolve(__dirname, '../fonts') const __fonts = resolve(__dirname, '../fonts')
const fonts: SatoriOptions['fonts'] = [ const loadFont = async (fontName: string, weight: number, style: string) => {
{ try {
name: 'Inter', const fontFile = resolve(__fonts, `${fontName}-${weight}.otf`)
data: await readFile(resolve(__fonts, 'Inter-Regular.otf')), const fontData = await readFile(fontFile)
weight: 400, return { name: fontName, data: fontData, weight, style }
style: 'normal' } catch (error) {
}, console.error(`Error loading font ${fontName} with weight ${weight}:`, error)
{ return null
name: 'Inter',
data: await readFile(resolve(__fonts, 'Inter-Medium.otf')),
weight: 500,
style: 'normal'
},
{
name: 'Inter',
data: await readFile(resolve(__fonts, 'Inter-SemiBold.otf')),
weight: 600,
style: 'normal'
},
{
name: 'Inter',
data: await readFile(resolve(__fonts, 'Inter-Bold.otf')),
weight: 700,
style: 'normal'
} }
] }
const fonts: SatoriOptions['fonts'] = [
await loadFont('Inter', 400, 'normal'),
await loadFont('Inter', 500, 'normal'),
await loadFont('Inter', 600, 'normal'),
await loadFont('Inter', 700, 'normal'),
].filter(font => font !== null)
export default defineSatoriConfig({ export default defineSatoriConfig({
width: 1200, width: 1200,
@ -40,8 +31,7 @@ export default defineSatoriConfig({
fonts, fonts,
props: { props: {
title: 'Title', title: 'Title',
description: description: `Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.`,
'Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.',
dir: '/j' dir: '/j'
} }
}) })