From 605ac9c6b9ee69292080b618a2cb0e39062130de Mon Sep 17 00:00:00 2001 From: codecalm Date: Mon, 2 Mar 2020 16:42:02 +0100 Subject: icons optimize --- gulpfile.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index beb3969..c5939f7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -51,16 +51,22 @@ gulp.task('icons-sprite', function (cb) { }); }); -gulp.task('optimize', function(){ - glob("_site/icons/*.svg", {}, function (er, files) { +gulp.task('optimize', function(cb){ + glob("_icons/*.svg", {}, function (er, files) { files.forEach(function (file, i) { let svgFile = fs.readFileSync(file), svgFileContent = svgFile.toString(); svgFileContent = svgFileContent - .replace(/><\/(polyline|line|rect|circle)>/, '/>') + .replace(/><\/(polyline|line|rect|circle|path)>/g, '/>') + .replace(/rx="([^"]+)"\s+ry="\1"/g, 'rx="$1"') + .replace(/\s?\/>/g, ' />') + .replace(/\n\s*<(line|circle|path|polyline)/g, "\n <$1") + .replace(/polyline points="([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s([0-9.]+)"/g, 'line x1="$1" y1="$2" x2="$3" y2="$4"') .replace(/\n\n+/g, "\n"); + + console.log('file', file); fs.writeFileSync(file, svgFileContent); }); -- cgit v1.2.1