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, "+");