Skip to content

Instantly share code, notes, and snippets.

@bfintal
Last active August 29, 2017 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bfintal/422e0146d6f7b91e9c77880c2ac09266 to your computer and use it in GitHub Desktop.
Save bfintal/422e0146d6f7b91e9c77880c2ac09266 to your computer and use it in GitHub Desktop.
gulp.task( 'google-font-download-list', function() {
var url = 'https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyDS1XfK5O1n2KXV3a1sonEffs966tQt54g';
return download( url )
.pipe( rename( {
basename: 'google-fonts',
extname: '.json'
} ) )
.pipe( gulp.dest( '.' ) );
} );
gulp.task( 'google-font-update-list', ['google-font-download-list'], function() {
var fonts = require( './google-fonts.json' );
var i, variants, subsets, php = '\n';
for ( i = 0; i < fonts.items.length; i++ ) {
variants = fonts.items[ i ].variants.join( '\', \'' );
if ( variants ) {
variants = '\'' + variants + '\'';
}
subsets = fonts.items[ i ].subsets.join( '\', \'' );
if ( subsets ) {
subsets = '\'' + subsets + '\'';
}
php += '\t\t\t\'' + fonts.items[ i ].family + '\' => array(\n\t\t\t\t\'variants\' => array( ' + variants + ' ),\n\t\t\t\t\'subsets\' => array( ' + subsets + ' ),\n\t\t\t),\n';
}
return gulp.src( './function-google-fonts.php' )
.pipe( replace( /(pbs_get_all_google_fonts\(\)\s*\{[\s\S]+return\s*array\()[^;]+/gm, '$1' + php + '\t\t)' ) )
.pipe( gulp.dest( '.' ) );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment