Skip to content

Commit

Permalink
KAD-4023 Action to update google fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
oakesjosh committed Jan 15, 2025
1 parent 473a8c3 commit 61eda89
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
35 changes: 32 additions & 3 deletions .github/scripts/update-fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,38 @@ function generateFontsArrayContent(fonts) {
*/\n\nreturn array(`;

fonts.items.forEach((font, index) => {
content += `'${font.family}' => array('v' => array(`;
content += `'${font.family}' => array(`;

// Variants
content += `'v' => array(`;
content += font.variants.map((v) => `'${v}'`).join(',');
content += `), 'c' => array('${font.category}'))`;
content += `),`;

// Subsets (scripts)
content += `'s' => array(`;
content += font.subsets.map((s) => `'${s}'`).join(',');
content += `),`;

// Weights - Extract unique weights from variants
const weights = font.variants
.map((v) => v.replace('italic', ''))
.filter((v) => v !== '')
.filter((v, i, arr) => arr.indexOf(v) === i);
content += `'w' => array(`;
content += weights.length ? weights.map((w) => `'${w}'`).join(',') : `'regular'`;
content += `),`;

// Styles - Check if font has italic variants
const styles = ['normal'];
if (font.variants.some((v) => v.includes('italic'))) {
styles.push('italic');
}
content += `'i' => array(`;
content += styles.map((s) => `'${s}'`).join(',');
content += `)`;

// Close font entry
content += `)`;
content += index === fonts.items.length - 1 ? '' : ',';
});

Expand Down Expand Up @@ -59,7 +88,7 @@ async function main() {
fs.writeFile('./includes/gfonts-names-array.php', fontNamesContent),
]);

console.log('Successfully updated ./includes/gfonts-array.php');
console.log('Successfully updated ./includes/gfonts-array.php and ./includes/gfonts-names-array.php');
} catch (error) {
console.error('Error:', error);
process.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion includes/gfonts-array.php

Large diffs are not rendered by default.

0 comments on commit 61eda89

Please sign in to comment.