diff --git a/lib/vocabulary.ts b/lib/vocabulary.ts index 74615e4..e716292 100644 --- a/lib/vocabulary.ts +++ b/lib/vocabulary.ts @@ -5,14 +5,25 @@ import cheerio from "cheerio"; const MY_DIR = __dirname; const SVG_DIR = path.join(MY_DIR, "..", "svg"); +function removeAttr(attr: string, $: cheerio.Root, g: cheerio.Cheerio) { + const items = g.find(`[${attr}]`); + items.each(function (this: any, i, el) { + $((this)).removeAttr(attr); + }); +} + export function build() { const filenames = fs.readdirSync(SVG_DIR); for (let filename of filenames) { if (path.extname(filename) === ".svg") { - const svg = fs.readFileSync(path.join(SVG_DIR, filename), { + const svgMarkup = fs.readFileSync(path.join(SVG_DIR, filename), { encoding: "utf-8", }); - console.log(filename, svg); + const $ = cheerio.load(svgMarkup); + const g = $("svg > g"); + removeAttr('fill', $, g); + removeAttr('stroke', $, g); + console.log(filename, g.html()); } } } diff --git a/package-lock.json b/package-lock.json index 6cd6964..3dd73dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -944,6 +944,14 @@ "to-fast-properties": "^2.0.0" } }, + "@types/cheerio": { + "version": "0.22.23", + "resolved": "https://registry.npmjs.org/@types/cheerio/-/cheerio-0.22.23.tgz", + "integrity": "sha512-QfHLujVMlGqcS/ePSf3Oe5hK3H8wi/yN2JYuxSB1U10VvW1fO3K8C+mURQesFYS1Hn7lspOsTT75SKq/XtydQg==", + "requires": { + "@types/node": "*" + } + }, "@types/node": { "version": "14.14.22", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.22.tgz", diff --git a/package.json b/package.json index d9e19f3..e4b50dd 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@babel/preset-env": "^7.12.11", "@babel/preset-typescript": "^7.12.7", "@babel/register": "^7.12.10", + "@types/cheerio": "^0.22.23", "@types/node": "^14.14.22", "cheerio": "^1.0.0-rc.5", "prettier": "^2.2.1",