Skip to content

Commit

Permalink
Update font-call.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
katydecorah committed Apr 21, 2024
1 parent f0c6a32 commit 3b9af49
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions components/font-call.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,6 @@
import { GeneratedData } from "./main-app";
import rtlSubsets from "../data/rtl.json";

export default function fontCall({
variants,
slug,
selectedVariant,
previewName,
}: {
variants: GeneratedData[number]["variants"];
slug: string;
selectedVariant: string;
previewName: string;
}): string {
let fontCallString = slug;

if (selectedVariant && selectedVariant !== "regular") {
fontCallString += fontCallSelectedVariant(selectedVariant);
}
// if font doesn't have regular variant, add subset to font call
if (!selectedVariant && !variants.includes("regular")) {
fontCallString += fontCallVariant(variants);
}

fontCallString += `&text=${encodeURIComponent(previewName)}&display=swap`;

return `https://fonts.googleapis.com/css2?family=${fontCallString}`;
}

export function fontCallVariant(
variants: GeneratedData[number]["variants"],
): string {
Expand Down Expand Up @@ -56,6 +30,32 @@ export function fontCallSelectedVariant(selectedVariant: string): string {
return `:${variants.join(",")}`;
}

export default function fontCall({
variants,
slug,
selectedVariant,
previewName,
}: {
variants: GeneratedData[number]["variants"];
slug: string;
selectedVariant: string;
previewName: string;
}): string {
let fontCallString = slug;

if (selectedVariant && selectedVariant !== "regular") {
fontCallString += fontCallSelectedVariant(selectedVariant);
}
// if font doesn't have regular variant, add subset to font call
if (!selectedVariant && !variants.includes("regular")) {
fontCallString += fontCallVariant(variants);
}

fontCallString += `&text=${encodeURIComponent(previewName)}&display=swap`;

return `https://fonts.googleapis.com/css2?family=${fontCallString}`;
}

export function familyStyle({
family,
selectedVariant,
Expand Down

0 comments on commit 3b9af49

Please sign in to comment.