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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/** @jsxImportSource https://esm.sh/react */
const preconnect = (
<>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="anonymous" />
</>
);
export function GoogleFonts({ family, weight }: {
family: string;
weight?: string;
}) {
const href = getLink({ family, weight });
return (
<>
{preconnect}
<link
rel="stylesheet"
href={href}
/>
</>
);
}
export const inconsolata = (
<>
{preconnect}
<link
href="https://fonts.googleapis.com/css2?family=Inconsolata:wght@200..900&display=swap"
rel="stylesheet"
/>
</>
);
export const sourceCodePro = (
<>
{preconnect}
<link
href="https://fonts.googleapis.com/css2?family=Source+Code+Pro:wght@400..700&display=swap"
rel="stylesheet"
/>
</>
);
export const robotoMono = <GoogleFonts family="Roboto+Mono" />;
const getLink = ({
family,
weight = "400..700",
}: {
family: string;
weight?: string;
}): string => `https://fonts.googleapis.com/css2?family=${replaceSpaces(family)}:wght@${weight}&display=swap`;
const replaceSpaces = (s: string) => s.replace(/ /g, "+");
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 16, 2024