From 0c0877269d4075c8588b900cf7c3874267c0349e Mon Sep 17 00:00:00 2001 From: codecalm Date: Tue, 10 Mar 2020 00:29:22 +0100 Subject: icons sprite --- gulpfile.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 3db1297..03f9d56 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -6,6 +6,33 @@ const gulp = require('gulp'), gulp.task('icons-sprite', function (cb) { + glob("_site/icons/*.svg", {}, function (er, files) { + + let svgContent = ''; + + files.forEach(function (file, i) { + let name = path.basename(file, '.svg'), + svgFile = fs.readFileSync(file), + svgFileContent = svgFile.toString(); + + svgFileContent = svgFileContent + .replace(/]+>/g, '') + .replace(/<\/svg>/g, '') + .replace(/\n+/g, '') + .replace(/>\s+<') + .trim(); + + svgContent += `${svgFileContent}` + }); + + let svg = `${svgContent}`; + + fs.writeFileSync('icons-sprite.svg', svg); + cb(); + }); +}); + +gulp.task('icons-preview', function (cb) { const columnsCount = 17, padding = 29, paddingOuter = 5, @@ -46,7 +73,7 @@ gulp.task('icons-sprite', function (cb) { const svgContent = `\n${svgContentSymbols}\n${svgContentIcons}\n`; - fs.writeFileSync('icons.svg', svgContent); + fs.writeFileSync('demo/icons.svg', svgContent); cb(); }); }); @@ -82,7 +109,7 @@ gulp.task('icons-stroke', function (cb) { const svgContent = `\n${svgContentSymbols}\n${svgContentIcons}\n`; - fs.writeFileSync('icons-stroke.svg', svgContent); + fs.writeFileSync('demo/icons-stroke.svg', svgContent); cb(); }); @@ -102,8 +129,6 @@ gulp.task('optimize', function (cb) { .replace(/\s+"/g, '"') .replace(/\n\n+/g, "\n"); - console.log('file', file); - fs.writeFileSync(file, svgFileContent); }); -- cgit v1.2.1