From ac27eef4e5ae43530e4505c712d83c83f964ec35 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Mon, 17 Apr 2023 12:26:55 +0800 Subject: [PATCH] fix(wi): update svgo config. --- icons/sn/.gitignore | 3 ++- icons/wi/svgo.config.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/icons/sn/.gitignore b/icons/sn/.gitignore index 942786ecaf..e10e29e402 100644 --- a/icons/sn/.gitignore +++ b/icons/sn/.gitignore @@ -6,4 +6,5 @@ !tsconfig.json !package.json !data -!README.md \ No newline at end of file +!README.md +!svgo.config.js \ No newline at end of file diff --git a/icons/wi/svgo.config.js b/icons/wi/svgo.config.js index 77b78f2422..4f1da0bc78 100644 --- a/icons/wi/svgo.config.js +++ b/icons/wi/svgo.config.js @@ -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: { @@ -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) + }, + } ] } \ No newline at end of file