@@ -21,6 +21,7 @@ def __init__(self, root_dir: str = "."):
21
21
self .root_dir = Path (root_dir )
22
22
self .docs_dir = self .root_dir / "docs"
23
23
self .src_dir = self .root_dir / "src"
24
+ self .openapi_dir = self .root_dir / "openapi-spec"
24
25
self .static_dir = self .root_dir / "static"
25
26
self .icons_dir = self .static_dir / "icons"
26
27
# Create image_analysis folder in the same directory as the script
@@ -57,9 +58,9 @@ def __init__(self, root_dir: str = "."):
57
58
r'["\']([^"\']*?/images/[^"\']*?\.(?:png|jpg|jpeg|gif|svg|webp))["\']' ,
58
59
]
59
60
60
- self .referenced_images = set ()
61
- self .static_images = set ()
62
- self .unused_images = set ()
61
+ self .referenced_images : Set [ str ] = set ()
62
+ self .static_images : Set [ str ] = set ()
63
+ self .unused_images : Set [ str ] = set ()
63
64
64
65
def find_all_static_images (self ) -> Set [str ]:
65
66
"""Find all images in the static directory (excluding icons)."""
@@ -95,6 +96,10 @@ def normalize_image_path(self, path: str) -> str:
95
96
path = path [8 :] # Remove '/static/'
96
97
elif path .startswith ('static/' ):
97
98
path = path [7 :] # Remove 'static/'
99
+ elif path .startswith ('/docs/' ):
100
+ path = path [6 :] # Remove '/docs/' (this maps to static directory)
101
+ elif path .startswith ('docs/' ):
102
+ path = path [5 :] # Remove 'docs/' (this maps to static directory)
98
103
elif path .startswith ('../../../static/' ):
99
104
path = path [16 :] # Remove '../../../static/' (16 characters)
100
105
elif path .startswith ('../../static/' ):
@@ -168,6 +173,32 @@ def find_referenced_images(self) -> Set[str]:
168
173
except Exception as e :
169
174
print (f" ⚠️ Error reading { file_path } : { e } " )
170
175
176
+ # Scan OpenAPI spec files (YAML)
177
+ if self .openapi_dir .exists ():
178
+ print (f" 📋 Scanning openapi-spec directory..." )
179
+ yaml_files = []
180
+ for pattern in ['**/*.yaml' , '**/*.yml' ]:
181
+ yaml_files .extend (glob .glob (str (self .openapi_dir / pattern ), recursive = True ))
182
+
183
+ print (f" 📋 Found { len (yaml_files )} YAML files" )
184
+ total_files += len (yaml_files )
185
+
186
+ for file_path in yaml_files :
187
+ try :
188
+ with open (file_path , 'r' , encoding = 'utf-8' ) as f :
189
+ content = f .read ()
190
+
191
+ # Apply all image patterns
192
+ for pattern in self .image_patterns :
193
+ matches = re .findall (pattern , content , re .IGNORECASE | re .MULTILINE )
194
+ for match in matches :
195
+ normalized_path = self .normalize_image_path (match )
196
+ if normalized_path :
197
+ referenced_images .add (normalized_path )
198
+
199
+ except Exception as e :
200
+ print (f" ⚠️ Error reading { file_path } : { e } " )
201
+
171
202
print (f"📊 Scanned { total_files } total files" )
172
203
print (f"📊 Found { len (referenced_images )} unique image references" )
173
204
return referenced_images
@@ -280,6 +311,7 @@ def save_results(self, results: Dict):
280
311
f .write ("- Properly handles markdown image syntax with alt text\n " )
281
312
f .write ("- Scans all .md and .mdx files in the /docs directory\n " )
282
313
f .write ("- Scans all .js, .jsx, .ts, .tsx, .css, .scss files in the /src directory\n " )
314
+ f .write ("- Scans all .yaml and .yml files in the /openapi-spec directory\n " )
283
315
f .write ("- Detects both image syntax (![...]) and link syntax ([...]) pointing to images\n " )
284
316
f .write ("- Excludes images in the /static/icons directory\n " )
285
317
f .write ("- Excludes specific ignored images (logos, etc.) from cleanup analysis\n " )
0 commit comments