diff --git a/components/font-call.ts b/components/font-call.ts index a2d99b2..2059140 100644 --- a/components/font-call.ts +++ b/components/font-call.ts @@ -1,6 +1,32 @@ 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 { @@ -14,7 +40,7 @@ export function fontCallVariant( return ""; } -function fontCallSelectedVariant(selectedVariant: string): string { +export function fontCallSelectedVariant(selectedVariant: string): string { const hasItalic = selectedVariant.includes("italic"); const variantNumber = selectedVariant.match(/\d+/g); // get number from selectedVariant @@ -55,29 +81,3 @@ export function familyStyle({ } return style; } - -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}`; -}