diff options
Diffstat (limited to 'gulpfile.js')
-rw-r--r-- | gulpfile.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/gulpfile.js b/gulpfile.js index b15d8b6a..6f55b35e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -399,6 +399,10 @@ gulp.task('icons-stroke', gulp.series('build-jekyll', function (cb) { })); gulp.task('optimize', function (cb) { + const addFloats = function(n1, n2) { + return Math.round((parseFloat(n1) + parseFloat(n2)) * 1000) / 1000 + }; + glob("src/_icons/*.svg", {}, function (er, files) { files.forEach(function (file, i) { @@ -412,7 +416,20 @@ gulp.task('optimize', function (cb) { .replace(/\n\s*<(line|circle|path|polyline|rect)/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(/a\s?([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s?([0-1])\s?([0-1])\s?(-?[0-9.]+)\s?(-?[0-9.]+)/g, 'a$1 $2 $3 $4 $5 $6 $7') - .replace(/\n\n+/g, "\n"); + .replace(/\n\n+/g, "\n") + + .replace(/<path d="M([0-9.]*) ([0-9.]*)l([-0-9.]*) ([-0-9.]*)"/g, function(f, r1, r2, r3, r4){ + return `<line x1="${r1}" y1="${r2}" x2="${addFloats(r1, r3)}" y2="${addFloats(r2, r4)}"`; + }) + .replace(/<path d="M([0-9.]*) ([0-9.]*)v([0-9.]*)"/g, function(f, r1, r2, r3){ + return `<line x1="${r1}" y1="${r2}" x2="${r1}" y2="${addFloats(r2, r3)}"`; + }) + .replace(/<path d="M([0-9.]*) ([0-9.]*)h([0-9.]*)"/g, function(f, r1, r2, r3){ + return `<line x1="${r1}" y1="${r2}" x2="${addFloats(r1, r3)}" y2="${r2}"`; + }); + + // + // if(svgFile.toString() !== svgFileContent) { fs.writeFileSync(file, svgFileContent); |