Skip to content

Commit 0d6a199

Browse files
authored
Merge pull request #1103 from elax46/dev
Fix bug and Reame file
2 parents b299a3e + 6a36dfa commit 0d6a199

File tree

11 files changed

+27
-5
lines changed

11 files changed

+27
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,11 @@ Do you like these icons? Support the project with a pizza 🍕🍕
192192
- Rules on Icon size and contraints are ([HERE](https://github.com/elax46/custom-brand-icons/discussions/1021),
193193
- The `svg` code must contain **viewbox**. No transform, translate, or scale.
194194
- Make sure to add color: **#44739e**. Every custom brand icon uses this color.
195+
- all icons must have a nomenclature NOT in camelcase but of the type `part1name-part2name`
195196
- Once done, add the svg file in the folder `icon-svg` found in the root of the repo.
196197

198+
- the icon must ***not be composed of multiple paths but a single** one as shown in the example below
199+
197200
Example svg file below:
198201

199202
```svg

custom-icons-builder.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,35 @@ function extractPath(svgContent) {
1010
return m ? m[1] : "";
1111
}
1212

13+
function extractViewBox(svgContent) {
14+
const m = svgContent.match(/<svg.+?viewBox="([^"]+)"/);
15+
if (m) {
16+
const parts = m[1].split(" ").map(Number);
17+
if (parts.length === 4) {
18+
return parts;
19+
} else {
20+
throw new Error("Invalid viewBox format: " + m[1]);
21+
}
22+
}
23+
// Fallback to default viewBox if not found
24+
return [0, 0, 24, 24];
25+
}
26+
1327
const files = fs.readdirSync(ICONS_DIR).filter(f => f.endsWith(".svg"));
1428

1529
let output = "var icons = {\n";
1630

1731
files.forEach(file => {
18-
const name = path.basename(file, ".svg");
19-
const svgContent = fs.readFileSync(path.join(ICONS_DIR, file), "utf8");
20-
const pathData = extractPath(svgContent);
21-
22-
output += ` "${name}":[0,0,24,24,${JSON.stringify(pathData)}],\n`;
32+
try {
33+
const name = path.basename(file, ".svg");
34+
const svgContent = fs.readFileSync(path.join(ICONS_DIR, file), "utf8");
35+
const pathData = extractPath(svgContent);
36+
const viewBox = extractViewBox(svgContent);
37+
38+
output += ` "${name}":[${viewBox.join(",")},${JSON.stringify(pathData)}],\n`;
39+
} catch (err) {
40+
console.log(`❌ Failed to process ${file}: ${err.message}`);
41+
}
2342
});
2443

2544
output += "};\n\n";

0 commit comments

Comments
 (0)