Skip to content

Commit

Permalink
fix(wi): update svgo config.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 17, 2023
1 parent 867b2d1 commit ac27eef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion icons/sn/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
!tsconfig.json
!package.json
!data
!README.md
!README.md
!svgo.config.js
34 changes: 34 additions & 0 deletions icons/wi/svgo.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
const REG = /(enable-background:new 0 0 30 30;?)/g;
const attrREG = /(onclick)/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['onclick'];
}
if (item.children) {
item.children = modify(item.children);
}
return item;
});
}

/** @type {import('svgo').Config} */
module.exports = {
multipass: true,
js2svg: {
Expand All @@ -13,5 +33,19 @@ module.exports = {
attributes: ['height="1em"', 'width="1em"']
}
},
{
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 ac27eef

Please sign in to comment.