Skip to content

Commit 289d926

Browse files
Only check stroke for icons in devicon.json's font objects (devicons#1491)
Co-authored-by: David Leal <[email protected]>
1 parent 41f626f commit 289d926

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

.github/scripts/build_assets/util.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from pathlib import Path
23
import re
34
from typing import List
45
import platform
@@ -71,11 +72,23 @@ def find_object_added_in_pr(icons: List[dict], pr_title: str):
7172
raise Exception(message)
7273

7374

75+
def is_svg_in_font_attribute(svg_file_path: Path, devicon_object: dict):
76+
"""
77+
Check if svg is in devicon.json's font attribute.
78+
:param svg_file_path, the path to a single svg icon
79+
:devicon_object, an object for a single icon inside devicon.json
80+
:return true if the svg exists in the devicon_object's font attribute, false if it doesn't
81+
"""
82+
icon_version = Path(svg_file_path).stem.split('-', 1)[1]
83+
font_object = devicon_object["versions"]["font"]
84+
return icon_version in font_object
85+
86+
7487
valid_svg_filename_pattern = re.compile(r"-(original|plain|line)(-wordmark)?\.svg$")
7588
def is_svg_name_valid(filename: str):
7689
return valid_svg_filename_pattern.search(filename) is not None
7790

91+
7892
valid_svg_version_pattern = re.compile(r"^(original|plain|line)(-wordmark)?$")
7993
def is_svg_version_valid(version):
8094
return valid_svg_version_pattern.search(version) is not None
81-

.github/scripts/check_icon_pr.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def main():
4242
print("No SVGs to check, ending script.")
4343
svg_err_msg = "Error checking SVGs: no SVGs to check. Might be caused by above issues."
4444
else:
45-
svg_err_msg = check_svgs(svgs)
45+
svg_err_msg = check_svgs(svgs, filtered_icon)
4646

4747
err_msg = []
4848
if devicon_err_msg != []:
@@ -163,7 +163,7 @@ def check_devicon_object(icon: dict):
163163
return ""
164164

165165

166-
def check_svgs(svg_file_paths: List[Path]):
166+
def check_svgs(svg_file_paths: List[Path], devicon_object: dict):
167167
"""
168168
Check the width, height, viewBox and style of each svgs passed in.
169169
The viewBox must be '0 0 128 128'.
@@ -195,10 +195,11 @@ def check_svgs(svg_file_paths: List[Path]):
195195
err_msg.append("- 'viewBox' is not '0 0 128 128' -> Set it or scale the file using https://www.iloveimg.com/resize-image/resize-svg.")
196196

197197
# goes through all elems and check for strokes
198-
for child in tree.iter():
199-
if child.get("stroke") != None:
200-
err_msg.append("- SVG contains `stroke` property. This will get ignored by Icomoon. Please convert them to fills.")
201-
break
198+
if util.is_svg_in_font_attribute(svg_path, devicon_object):
199+
for child in tree.iter():
200+
if child.get("stroke") != None:
201+
err_msg.append("- SVG contains `stroke` property. This will get ignored by Icomoon. Please convert them to fills.")
202+
break
202203

203204
if len(err_msg) > 1:
204205
err_msgs.append("\n".join(err_msg))

0 commit comments

Comments
 (0)