Leaflet Blog in Deno Fresh
1// from https://github.com/kosei28/vercel-og-google-fonts/blob/main/src/utils/font.ts
2export async function loadGoogleFont(font: string, text: string) {
3 const url = `https://fonts.googleapis.com/css2?family=${font}&text=${encodeURIComponent(
4 text,
5 )}`;
6
7 const css = await (await fetch(url)).text();
8
9 const resource = css.match(
10 /src: url\((.+)\) format\('(opentype|truetype)'\)/,
11 );
12
13 if (resource) {
14 const res = await fetch(resource[1]);
15 if (res.status == 200) {
16 return await res.arrayBuffer();
17 }
18 }
19
20 throw new Error("failed to load font data");
21}