don't replace fill/stroke of 'none'.
rodzic
511ea2510b
commit
66fc1caaac
File diff suppressed because one or more lines are too long
|
@ -2,23 +2,27 @@ import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import cheerio from "cheerio";
|
import cheerio from "cheerio";
|
||||||
|
|
||||||
export type Symbol = {
|
export type SvgSymbolData = {
|
||||||
name: string;
|
name: string;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
svg: string;
|
svg: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SerializedVocabulary = Symbol[];
|
|
||||||
|
|
||||||
const MY_DIR = __dirname;
|
const MY_DIR = __dirname;
|
||||||
const SVG_DIR = path.join(MY_DIR, "..", "svg");
|
const SVG_DIR = path.join(MY_DIR, "..", "svg");
|
||||||
const VOCAB_PATH = path.join(MY_DIR, "svg-vocabulary.json");
|
const VOCAB_PATH = path.join(MY_DIR, "svg-vocabulary.json");
|
||||||
|
|
||||||
function removeAttr(attr: string, $: cheerio.Root, g: cheerio.Cheerio) {
|
function removeAttrIfNotNone(
|
||||||
|
attr: string,
|
||||||
|
$: cheerio.Root,
|
||||||
|
g: cheerio.Cheerio
|
||||||
|
) {
|
||||||
const items = g.find(`[${attr}]`);
|
const items = g.find(`[${attr}]`);
|
||||||
items.each(function (this: any, i, el) {
|
items.each(function (this: any, i, el) {
|
||||||
$(this).removeAttr(attr);
|
if ($(this).attr(attr) !== "none") {
|
||||||
|
$(this).removeAttr(attr);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +42,7 @@ function getSvgPixelDimension($: cheerio.Root, attr: string): number {
|
||||||
|
|
||||||
export function build() {
|
export function build() {
|
||||||
const filenames = fs.readdirSync(SVG_DIR);
|
const filenames = fs.readdirSync(SVG_DIR);
|
||||||
const vocab: SerializedVocabulary = [];
|
const vocab: SvgSymbolData[] = [];
|
||||||
for (let filename of filenames) {
|
for (let filename of filenames) {
|
||||||
if (path.extname(filename) === ".svg") {
|
if (path.extname(filename) === ".svg") {
|
||||||
console.log(`Adding ${filename} to vocabulary.`);
|
console.log(`Adding ${filename} to vocabulary.`);
|
||||||
|
@ -49,8 +53,8 @@ export function build() {
|
||||||
const width = getSvgPixelDimension($, "width");
|
const width = getSvgPixelDimension($, "width");
|
||||||
const height = getSvgPixelDimension($, "height");
|
const height = getSvgPixelDimension($, "height");
|
||||||
const g = $("svg > g");
|
const g = $("svg > g");
|
||||||
removeAttr("fill", $, g);
|
removeAttrIfNotNone("fill", $, g);
|
||||||
removeAttr("stroke", $, g);
|
removeAttrIfNotNone("stroke", $, g);
|
||||||
const name = g.attr("id");
|
const name = g.attr("id");
|
||||||
if (!name) {
|
if (!name) {
|
||||||
throw new Error(`${filename} has no <g> with an 'id' attribute!`);
|
throw new Error(`${filename} has no <g> with an 'id' attribute!`);
|
||||||
|
@ -59,7 +63,7 @@ export function build() {
|
||||||
if (!svg) {
|
if (!svg) {
|
||||||
throw new Error(`${filename} has no <g> with child elements!`);
|
throw new Error(`${filename} has no <g> with child elements!`);
|
||||||
}
|
}
|
||||||
const symbol: Symbol = {
|
const symbol: SvgSymbolData = {
|
||||||
name,
|
name,
|
||||||
svg,
|
svg,
|
||||||
width,
|
width,
|
||||||
|
|
Ładowanie…
Reference in New Issue