From 9e3f11bf05d9c3883b99afe900ea6cb7c2392111 Mon Sep 17 00:00:00 2001 From: codecalm Date: Sun, 1 Mar 2020 16:06:35 +0100 Subject: heart, user, map pin, gulp init --- gulpfile.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 gulpfile.js (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..f5bedd1 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,52 @@ +const gulp = require('gulp'), + glob = require("glob"), + fs = require("fs"), + path = require("path"), + svg2img = require('svg2img'); + + +gulp.task('icons-sprite', function (cb) { + const columnsCount = 20, + padding = 16, + paddingOuter = 49, + iconSize = 24; + + glob("_site/icons/*.svg", {}, function (er, files) { + const iconsCount = files.length, + rowsCount = Math.ceil(iconsCount / columnsCount), + width = columnsCount * (iconSize + padding) + 2 * paddingOuter - padding, + height = rowsCount * (iconSize + padding) + 2 * paddingOuter - padding; + + let svgContentSymbols = '', + svgContentIcons = '', + x = paddingOuter, + y = paddingOuter; + files.forEach(function (file, i) { + let name = path.basename(file, '.svg'); + + let svgFile = fs.readFileSync(file), + svgFileContent = svgFile.toString(); + + svgFileContent = svgFileContent + .replace('', '') + .replace(/\n\s+/g, ''); + + svgContentSymbols += `\t${svgFileContent}\n`; + svgContentIcons += `\t\n`; + + x += padding + iconSize; + + if (i % columnsCount === columnsCount - 1) { + x = paddingOuter; + y += padding + iconSize; + } + }); + + const svgContent = `\n${svgContentSymbols}\n${svgContentIcons}\n`; + + fs.writeFileSync('icons.svg', svgContent); + cb(); + }); +}); -- cgit v1.2.1