Skip to content

Commit

Permalink
fix(sn): update svgo config.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 17, 2023
1 parent e8a2b8e commit 867b2d1
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions icons/sn/svgo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const REG = /(block-progression:tb'?)/g;
const attrREG = /(vectornator:layerName)/g;

function modify(children = []) {
return children.map((item) => {
const str = item.attributes?.['style'];
if (str && REG.test(str)) {
item.attributes['style'] = str.replace(REG, '');
}
if (attrREG.test(Object.keys(item.attributes || {}).join(','))) {
delete item.attributes['vectornator:layerName'];
}
if (item.children) {
item.children = modify(item.children);
}
return item;
});
}

/** @type {import('svgo').Config} */
module.exports = {
multipass: true,
js2svg: {
indent: 2, // string with spaces or number of spaces. 4 by default
pretty: true, // boolean, false by default
},
plugins: [
'removeComments',
'removeDimensions',
'cleanupAttrs',
{
name: 'removeAttrs',
fn: (ast, params, info) => {
delete ast.children[0]?.attributes['style'];
delete ast.children[0]?.attributes['xml:space'];
delete ast.children[0]?.attributes['xmlns:vectornator'];
ast.children[0]?.children.forEach((item) => {
if (item.name === 'a') {
ast.children[0].children = [...item.children];
}
});
ast.children = modify(ast.children)
},
}
]
}

0 comments on commit 867b2d1

Please sign in to comment.