From 867b2d1b54ccd05bb495be401c7c6bf8e7ee618f Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Mon, 17 Apr 2023 12:26:08 +0800 Subject: [PATCH] fix(sn): update svgo config. --- icons/sn/svgo.config.js | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 icons/sn/svgo.config.js diff --git a/icons/sn/svgo.config.js b/icons/sn/svgo.config.js new file mode 100644 index 000000000..72d58cdce --- /dev/null +++ b/icons/sn/svgo.config.js @@ -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) + }, + } + ] +}