| 
									
										
										
										
											2022-08-16 18:51:58 +02:00
										 |  |  | import pathlib | 
					
						
							|  |  |  | from pathlib import Path | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | root = pathlib.Path(__file__).parent.resolve() | 
					
						
							| 
									
										
										
										
											2023-04-17 00:04:08 +02:00
										 |  |  | template_path = root / "TEMPLATE.md" | 
					
						
							|  |  |  | path = root / "../ICONS.md" | 
					
						
							| 
									
										
										
										
											2022-08-16 18:51:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def generate_img_tag(file): | 
					
						
							| 
									
										
										
										
											2023-04-19 01:34:03 +10:00
										 |  |  |     return f'<a href="https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/{file.name}"><img src="https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/{file.name}" alt="{file.stem}" height="50"></a>' | 
					
						
							| 
									
										
										
										
											2022-08-16 18:51:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | imgs = sorted(Path("./png").glob("*.png")) | 
					
						
							|  |  |  | img_tags = [generate_img_tag(x) for x in imgs] | 
					
						
							|  |  |  | line_number = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Read the template file | 
					
						
							| 
									
										
										
										
											2023-04-17 00:04:08 +02:00
										 |  |  | with open(template_path, "r", encoding="UTF-8") as f: | 
					
						
							| 
									
										
										
										
											2022-08-16 18:51:58 +02:00
										 |  |  |     lines = f.readlines() | 
					
						
							|  |  |  | # Find the line that starts with "<!-- ICONS -->" | 
					
						
							|  |  |  | for line in lines: | 
					
						
							|  |  |  |     if line.startswith("<!-- ICONS -->"): | 
					
						
							|  |  |  |         line_number = lines.index(line) | 
					
						
							|  |  |  |         break | 
					
						
							|  |  |  | # Insert the icons after the line | 
					
						
							|  |  |  | lines.insert(line_number + 1, " ".join(img_tags)) | 
					
						
							|  |  |  | # Write the new file | 
					
						
							| 
									
										
										
										
											2023-04-17 00:04:08 +02:00
										 |  |  | with open(path, "w", encoding="UTF-8") as f: | 
					
						
							| 
									
										
										
										
											2022-08-16 18:51:58 +02:00
										 |  |  |     f.write("".join(lines)) | 
					
						
							|  |  |  |     f.write("\n") | 
					
						
							|  |  |  | print("Done!") | 
					
						
							| 
									
										
										
										
											2023-04-16 15:30:48 +02:00
										 |  |  | print("Please commit the new ICONS.md file.") |