mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-06-05 19:35:27 -04:00
4858c8928c
- Replaced GeistSans and GeistMono with Inter and JetBrainsMono in globals.css and layout.tsx. - Updated font variable names to reflect the new font choices in fonts.ts.
32 lines
987 B
TypeScript
32 lines
987 B
TypeScript
import { cacheLife } from "next/cache";
|
|
|
|
// Load a Google Font from the Google Fonts API
|
|
// Adapted from https://github.com/brianlovin/briOS/blob/f72dc33a11194de45c80337b22be4560da62ad7e/src/lib/og-utils.tsx#L32
|
|
export async function loadGoogleFont(font: string, weight: number): Promise<ArrayBuffer> {
|
|
"use cache";
|
|
|
|
const url = `https://fonts.googleapis.com/css2?family=${font}:wght@${weight}`;
|
|
|
|
const cssResponse = await fetch(url, {
|
|
next: {
|
|
revalidate: 31_536_000, // 1 year
|
|
},
|
|
});
|
|
const css = await cssResponse.text();
|
|
const resource = css.match(/src: url\((.+)\) format\('(opentype|truetype)'\)/);
|
|
|
|
if (resource) {
|
|
const fontResponse = await fetch(resource[1], {
|
|
next: {
|
|
revalidate: 31_536_000, // 1 year
|
|
},
|
|
});
|
|
if (fontResponse.status === 200) {
|
|
cacheLife("max"); // cache indefinitely if successful
|
|
return fontResponse.arrayBuffer();
|
|
}
|
|
}
|
|
|
|
throw new Error(`Failed to load font: ${font} ${weight}`);
|
|
}
|