Update [slug].png.ts 83cd4376
Testing custom font in OG
Steve Simkins · 2023-12-26 22:58 1 file(s) · +5 −8
src/pages/og-image/[slug].png.ts +5 −8
5 5
import { Resvg } from "@resvg/resvg-js";
6 6
import siteConfig from "@/site-config";
7 7
import { getFormattedDate } from "@/utils";
8 +
import fs from "fs";
8 9
9 -
const monoFontReg = await fetch(
10 -
  "https://api.fontsource.org/v1/fonts/roboto-mono/latin-400-normal.ttf"
11 -
);
10 +
const monoFontReg = await fs.readFile("/CommitMono-400-Regular.otf")
12 11
13 -
const monoFontBold = await fetch(
14 -
  "https://api.fontsource.org/v1/fonts/roboto-mono/latin-700-normal.ttf"
15 -
);
12 +
const monoFontBold = await fs.readFile("/CommitMono-700-Regular.otf")
16 13
17 14
const ogOptions: SatoriOptions = {
18 15
  width: 1200,
22 19
  fonts: [
23 20
    {
24 21
      name: "Roboto Mono",
25 -
      data: await monoFontReg.arrayBuffer(),
22 +
      data: await monoFontReg.buffer(),
26 23
      weight: 400,
27 24
      style: "normal",
28 25
    },
29 26
    {
30 27
      name: "Roboto Mono",
31 -
      data: await monoFontBold.arrayBuffer(),
28 +
      data: await monoFontBold.buffer(),
32 29
      weight: 700,
33 30
      style: "normal",
34 31
    },