import pathlib from pathlib import Path import sys def generate_img_tag(file): return ( f'' f'' ) if __name__ == "__main__": root = pathlib.Path(__file__).parent.resolve() template_path = root / "TEMPLATE.md" icons_md_path = root.parent / "ICONS.md" imgs = sorted((root.parent / "webp").glob("*.webp")) img_tags = [generate_img_tag(x) for x in imgs] # Read the template file with open(template_path, "r", encoding="UTF-8") as f: lines = f.readlines() # Find the line that starts with "" try: line_number = lines.index("\n") except ValueError: print(" placeholder not found in TEMPLATE.md") sys.exit(1) # Insert the icons after the placeholder lines.insert(line_number + 1, " ".join(img_tags) + "\n") # Write the new ICONS.md file with open(icons_md_path, "w", encoding="UTF-8") as f: f.writelines(lines) print("ICONS.md has been successfully generated.")