From 1bf438a471e41980c2093bf11d085f99e185ac06 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Mon, 17 Apr 2023 10:08:42 +0800 Subject: [PATCH] fix(is): add svgo config. --- icons/is/svgo.config.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 icons/is/svgo.config.js diff --git a/icons/is/svgo.config.js b/icons/is/svgo.config.js new file mode 100644 index 000000000..100651be9 --- /dev/null +++ b/icons/is/svgo.config.js @@ -0,0 +1,41 @@ +const REG = /(enable-background:accumulate;?|-inkscape-font-specification:Open Sans;?|block-progression:tb;?|-inkscape-font-specification:Sans;?|-inkscape-font-specification:'Open Sans Bold';?|writing-mode:lr-tb;?|enable-background:new;?|color-interpolation-filters:linearRGB;?|solid-opacity:1;?|color-interpolation-filters:sRGB|color-interpolation-filters:linearRGB;?|solid-color:#000;?)/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 (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']; + ast.children[0]?.children.forEach((item) => { + if (item.name === 'a') { + ast.children[0].children = [...item.children]; + } + }); + ast.children = modify(ast.children) + }, + } + ] +}