Skip to content

Commit

Permalink
fix(wl): update svgo config.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 17, 2023
1 parent 4ae40b3 commit e8a2b8e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions icons/wl/svgo.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
const REG = /(block-progression:tb;?|-inkscape-font-specification:(Sans|Helvetica Neue Bold|Bitstream Vera Sans|Open Sans Bold);?)/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 e8a2b8e

Please sign in to comment.