You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.4 KiB

1 year ago
  1. /**
  2. * manually run this file to generate array for google fonts inc/customizer/google-font-variants.php file)
  3. * run the script on a page with a div with class .google-fonts class.
  4. * you'll also need to put in a google webfonts api key.
  5. */
  6. $.getJSON('https://www.googleapis.com/webfonts/v1/webfonts?key={{API_KEY}}', function(data) {
  7. $.each( data.items, function( index, font ) {
  8. var category = [];
  9. category.push( font.category );
  10. var variants = font.variants;
  11. var weights = font.variants.slice();
  12. var styles = ['normal'];
  13. for( var i = 0; i < weights.length; i++){
  14. if ( weights[i].includes('italic') ) {
  15. weights.splice(i, 1);
  16. }
  17. };
  18. if ( variants.includes('italic') ) {
  19. styles.push('italic');
  20. }
  21. $('.google-fonts').append("'" + font.family + "' => array( 'v' => array(");
  22. for(var i = 0; i < variants.length; i++) {
  23. if( 0 === i ) {
  24. $('.google-fonts').append("'" + variants[i] + "'");
  25. } else {
  26. $('.google-fonts').append(",'" + variants[i] + "'");
  27. }
  28. }
  29. $('.google-fonts').append(")" + ",'c' => array(");
  30. for(var i = 0; i < category.length; i++) {
  31. if( 0 === i ) {
  32. $('.google-fonts').append("'" + category[i] + "'");
  33. } else {
  34. $('.google-fonts').append(",'" + category[i] + "'");
  35. }
  36. }
  37. $('.google-fonts').append(")" + "),");
  38. });
  39. });