Skip to content

Commit

Permalink
Implemented Update svg-sprites.svg syntax Rush#28
Browse files Browse the repository at this point in the history
Great suggestion and works really well.
  • Loading branch information
nikgavalas authored and midnightveil committed Nov 21, 2024
1 parent 43701fa commit 1f53328
Show file tree
Hide file tree
Showing 2 changed files with 599 additions and 794 deletions.
11 changes: 5 additions & 6 deletions lib/generateSprites.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ var Promise = require("bluebird"),
getIconSvg = require("./getIconSvg");

var svgo = new SVGO({
removeViewBox: true
removeViewBox: false
});

function generateSprite(name, params) {

return new Promise(function(resolve, reject) {
svgo.optimize(getIconSvg(params), function(result) {

var viewBox = result.data.match(/viewBox="(.*?)"/)[0];
var m = result.data.match('(<path.*\/>)');

var svgPath = m[1].replace('path', 'path id="fa-' + name + '"');
var svgPath = '<symbol id="fa-' + name + '" ' + viewBox + '>' + m[1] + '</symbol>';

resolve(svgPath.replace(/\s*fill="[^"]+"/, ''));
});
Expand All @@ -36,9 +36,8 @@ function generateSprites(glyphs, params) {
});
return Promise.all(workChain).then(function(lines) {
var outSvgSheet = fs.createWriteStream(outPath);
outSvgSheet.write('<?xml version="1.0" encoding="utf-8"?>\n');
outSvgSheet.write('<svg height="0" width="0" style="position:absolute;margin-left: -100%;">\n');
outSvgSheet.write(lines.join('\n'));
outSvgSheet.write('<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">\n');
outSvgSheet.write('\t' + lines.join('\n\t'));
outSvgSheet.end('\n<\/svg>\n');
});
}
Expand Down
Loading

0 comments on commit 1f53328

Please sign in to comment.