Skip to content

Commit 97aaff1

Browse files
committed
fix: use google font
1 parent d6aed36 commit 97aaff1

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

lib/watermark.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
import fs from 'node:fs/promises';
2-
import path from 'node:path';
31
import sharp from 'sharp';
42
import type { Blend } from './enumerations';
53

6-
const FONT_PATH = path.resolve(process.cwd(), 'public/fonts/Inter-Bold.woff2');
4+
const GOOGLE_FONTS_INTER_BOLD_URL =
5+
'https://fonts.gstatic.com/s/inter/v18/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZ9hiJ-Ek-_EeA.woff2';
76

8-
/** Module-level singleton so the file is only read once per process. */
97
let _fontDataUri: Promise<string> | null = null;
108

119
const getFontDataUri = (): Promise<string> => {
1210
if (!_fontDataUri) {
13-
_fontDataUri = fs
14-
.readFile(FONT_PATH)
15-
.then((buf) => `data:font/woff2;base64,${buf.toString('base64')}`)
16-
.catch(() => {
17-
// Font file missing — fall back to generic family names and hope
18-
// for the best. Log a warning so this is visible in prod logs.
19-
console.warn(
20-
'[watermark] Inter-Bold.woff2 not found at',
21-
FONT_PATH,
22-
'— text may be invisible in environments without system fonts.'
23-
);
11+
_fontDataUri = fetch(GOOGLE_FONTS_INTER_BOLD_URL)
12+
.then(async (res) => {
13+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
14+
const arrayBuffer = await res.arrayBuffer();
15+
const b64 = Buffer.from(arrayBuffer).toString('base64');
16+
return `data:font/woff2;base64,${b64}`;
17+
})
18+
.catch((err) => {
19+
console.warn('[watermark] Failed to fetch Inter Bold from Google Fonts:', err?.message);
2420
return '';
2521
});
2622
}

0 commit comments

Comments
 (0)