import os import re # Mapping of service title to subdirectory name mapping = { "Sandiviç Panel İndirme Kaldırma": "sandiviçpanelindirmekaldırma", "Konteyner Nakliyesi & Tiny House Kaldırma": "Konteyner nakliyesi Tiny house kaldırma", "Jet Ground Kaldırma Taşıma": "Jet ground kaldırma taşıma", "Vinç Hizmetleri": "Vinç hizmetleri", "Sepetli Platform Hizmetleri": "Sepetli platform hizmetleri", "Tekne ve Yat Kaldırma": "Tekne yat kaldırma", "Nakliyat ve Taşımacılık": "Nakliyat-Taşımacılık" } data_file = 'lib/data.ts' with open(data_file, 'r', encoding='utf-8') as f: content = f.read() for title, subdir in mapping.items(): image_dir = os.path.join('public/images', subdir) if os.path.exists(image_dir): files = [f for f in os.listdir(image_dir) if f.lower().endswith(('.png', '.jpg', '.jpeg', '.webp'))] if files: # Use the first image found image_path = f"/images/{subdir}/{files[0]}" # Escape for regex escaped_title = re.escape(title) pattern = rf'(title:\s*"{escaped_title}",\s*description:\s*".*?",\s*image:\s*")([^"]+)(")' content = re.sub(pattern, rf'\1{image_path}\3', content) with open(data_file, 'w', encoding='utf-8') as f: f.write(content) print("Successfully updated lib/data.ts with local images.")