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 a7d579b commit f0c6a32
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions components/font-call.ts
Original file line number Diff line number Diff line change
@@ -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);

Check failure on line 18 in components/font-call.ts

View workflow job for this annotation

GitHub Actions / build

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

Check failure on line 22 in components/font-call.ts

View workflow job for this annotation

GitHub Actions / build

'fontCallVariant' was used before it was defined
}

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

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

export function fontCallVariant(
variants: GeneratedData[number]["variants"],
): string {
Expand All @@ -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

Expand Down Expand Up @@ -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}`;
}

0 comments on commit f0c6a32

Please sign in to comment.