From c7f6b4a0bed18b311cba24515f700df63f7ef4c1 Mon Sep 17 00:00:00 2001 From: maropboia <164220066+maropboia@users.noreply.github.com> Date: Fri, 3 May 2024 11:38:44 +0600 Subject: [PATCH] improve --- .vitepress/hooks/satoriConfig.ts | 44 ++++++++++++-------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/.vitepress/hooks/satoriConfig.ts b/.vitepress/hooks/satoriConfig.ts index 30a380180..fbe480da2 100644 --- a/.vitepress/hooks/satoriConfig.ts +++ b/.vitepress/hooks/satoriConfig.ts @@ -7,32 +7,23 @@ import { defineSatoriConfig } from 'x-satori/vue' const __dirname = dirname(fileURLToPath(import.meta.url)) const __fonts = resolve(__dirname, '../fonts') -const fonts: SatoriOptions['fonts'] = [ - { - name: 'Inter', - data: await readFile(resolve(__fonts, 'Inter-Regular.otf')), - weight: 400, - style: 'normal' - }, - { - 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 loadFont = async (fontName: string, weight: number, style: string) => { + try { + const fontFile = resolve(__fonts, `${fontName}-${weight}.otf`) + const fontData = await readFile(fontFile) + return { name: fontName, data: fontData, weight, style } + } catch (error) { + console.error(`Error loading font ${fontName} with weight ${weight}:`, error) + return null } -] +} + +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({ width: 1200, @@ -40,8 +31,7 @@ export default defineSatoriConfig({ fonts, props: { title: 'Title', - description: - 'Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.', + description: `Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.`, dir: '/j' } })