forked from piotrkulpinski/openalternative
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfonts.ts
41 lines (36 loc) · 1014 Bytes
/
fonts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import localFont from "next/font/local"
import type { FontWeight } from "satori"
export const UncutSans = localFont({
variable: "--font-uncut-sans",
display: "swap",
src: [
{
path: "../public/fonts/UncutSans-Variable.woff2",
weight: "400 900",
style: "normal",
},
],
})
export const GeistSans = localFont({
variable: "--font-geist-sans",
display: "swap",
src: [
{
path: "../public/fonts/GeistSans-Variable.woff2",
weight: "400 900",
style: "normal",
},
],
})
export const loadGoogleFont = async (font: string, weight: FontWeight) => {
const url = `https://fonts.googleapis.com/css2?family=${font}:wght@${weight}`
const css = await (await fetch(url)).text()
const resource = css.match(/src: url\((.+)\) format\('(opentype|truetype)'\)/)
if (resource) {
const response = await fetch(resource[1])
if (response.status === 200) {
return await response.arrayBuffer()
}
}
throw new Error("failed to load font data")
}