Skip to content

Commit

Permalink
fix: fix og zh-cn font (#11)
Browse files Browse the repository at this point in the history
* fix: fix og zh-cn font

* fix: fix fontname
  • Loading branch information
liruifengv authored May 15, 2024
1 parent 58e62a9 commit 10f68cd
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/utils/generateOgImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ import { SITE } from "@config";
import { writeFile } from "node:fs/promises";
import { Resvg } from "@resvg/resvg-js";

const isDev = import.meta.env.DEV;
const website = isDev ? "http://localhost:4321/" : SITE.website;

const fetchFonts = async () => {
// Regular Font
const fontFileRegular = await fetch(
"https://www.1001fonts.com/download/font/ibm-plex-mono.regular.ttf"
`${website}fonts/NotoSansSC/static/NotoSansSC-Regular.ttf`
);
const fontRegular: ArrayBuffer = await fontFileRegular.arrayBuffer();

// Bold Font
const fontFileBold = await fetch(
"https://www.1001fonts.com/download/font/ibm-plex-mono.bold.ttf"
);
const fontBold: ArrayBuffer = await fontFileBold.arrayBuffer();

return { fontRegular, fontBold };
return { fontRegular };
};

const { fontRegular, fontBold } = await fetchFonts();
const { fontRegular } = await fetchFonts();

const ogImage = (text: string) => {
return (
Expand Down Expand Up @@ -121,25 +118,19 @@ const options: SatoriOptions = {
embedFont: true,
fonts: [
{
name: "IBM Plex Mono",
name: "NotoSansSC-Regular",
data: fontRegular,
weight: 400,
style: "normal",
},
{
name: "IBM Plex Mono",
data: fontBold,
weight: 600,
style: "normal",
},
],
};

const generateOgImage = async (mytext = SITE.title) => {
const svg = await satori(ogImage(mytext), options);

// render png in production mode
if (import.meta.env.MODE === "production") {
if (!isDev) {
const resvg = new Resvg(svg);
const pngData = resvg.render();
const pngBuffer = pngData.asPng();
Expand Down

0 comments on commit 10f68cd

Please sign in to comment.