Skip to content

Commit

Permalink
fix: variable paths including square brackets (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuhito committed Aug 2, 2023
1 parent e0d9de8 commit c10ed68
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
13 changes: 2 additions & 11 deletions packages/cli/src/google/packager-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ const packagerV2 = async (id: string, opts: BuildOptions) => {
const cssStyle: string[] = [];

for (const subset of unicodeKeys) {
// Remove brackets from unicode subset
const cleanedSubset = subset.replace('[', '').replace(']', '');

// Some fonts may have variants 400, 400i, 700 but not 700i.
if (style in variants[weight]) {
const fontObj = {
Expand All @@ -34,17 +31,11 @@ const packagerV2 = async (id: string, opts: BuildOptions) => {
unicodeRange: unicodeRange[subset],
src: [
{
url: makeFontFilePath(
id,
cleanedSubset,
weight,
style,
'woff2'
),
url: makeFontFilePath(id, subset, weight, style, 'woff2'),
format: 'woff2' as const,
},
{
url: makeFontFilePath(id, cleanedSubset, weight, style, 'woff'),
url: makeFontFilePath(id, subset, weight, style, 'woff'),
format: 'woff' as const,
},
],
Expand Down
10 changes: 1 addition & 9 deletions packages/cli/src/google/packager-variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ const packagerVariable = async (id: string, opts: BuildOptions) => {
const cssStyle: string[] = [];

for (const subset of Object.keys(variant[style])) {
// Remove brackets from unicode subset
const cleanedSubset = subset.replace('[', '').replace(']', '');

const fontObj: FontObject = {
family: font.family,
style,
Expand All @@ -46,12 +43,7 @@ const packagerVariable = async (id: string, opts: BuildOptions) => {
variable: variableOpts,
src: [
{
url: makeVariableFontFilePath(
id,
cleanedSubset,
axesLower,
style
),
url: makeVariableFontFilePath(id, subset, axesLower, style),
format: 'woff2-variations',
},
],
Expand Down
16 changes: 12 additions & 4 deletions packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const cleanPaths = (str: string): string =>
str.replace('[', '').replace(']', '');

// Used to determine where the downloader should save the files
const makeFontDownloadPath = (
fontDir: string,
Expand All @@ -7,7 +10,9 @@ const makeFontDownloadPath = (
style: string,
extension: string
): string =>
`${fontDir}/files/${fontId}-${subset}-${weight}-${style}.${extension}`;
cleanPaths(
`${fontDir}/files/${fontId}-${subset}-${weight}-${style}.${extension}`
);

// Some axes are all uppercase making packages inconsistent
const makeVariableFontDownloadPath = (
Expand All @@ -17,7 +22,9 @@ const makeVariableFontDownloadPath = (
axes: string,
style: string
): string =>
`${fontDir}/files/${fontId}-${subset}-${axes.toLowerCase()}-${style}.woff2`;
cleanPaths(
`${fontDir}/files/${fontId}-${subset}-${axes.toLowerCase()}-${style}.woff2`
);

// Used for the src urls in CSS files
const makeFontFilePath = (
Expand All @@ -26,14 +33,15 @@ const makeFontFilePath = (
weight: number,
style: string,
extension: string
): string => `./files/${fontId}-${subset}-${weight}-${style}.${extension}`;
): string =>
cleanPaths(`./files/${fontId}-${subset}-${weight}-${style}.${extension}`);

const makeVariableFontFilePath = (
fontId: string,
subset: string,
axes: string,
style: string
): string => `./files/${fontId}-${subset}-${axes}-${style}.woff2`;
): string => cleanPaths(`./files/${fontId}-${subset}-${axes}-${style}.woff2`);

// Insert a weight array to find the closest number given num - used for index.css gen
const findClosest = (arr: number[], num: number): number => {
Expand Down

0 comments on commit c10ed68

Please sign in to comment.