const fs = require('fs'); const path = require('path'); const urls = JSON.parse(fs.readFileSync(path.join(__dirname, 'cloudinary-urls-images.json'), 'utf-8')); const FILES = ['index.html', 'about.html', 'contact.html', 'courses.html', 'services.html', 'team.html', 'css/custom.css']; const CLOUD_BASE = 'https://res.cloudinary.com/du7xohbct/image/upload/f_auto,q_auto'; let totalReplacements = 0; for (const file of FILES) { const filePath = path.join(__dirname, file); if (!fs.existsSync(filePath)) continue; let content = fs.readFileSync(filePath, 'utf-8'); let fileCount = 0; for (const [filename, cloudUrl] of Object.entries(urls)) { // Add f_auto,q_auto optimization to URL const optimizedUrl = cloudUrl.replace('/image/upload/', '/image/upload/f_auto,q_auto/'); const localPath = `images/${filename}`; // Escape for regex const escaped = localPath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); const regex = new RegExp(escaped, 'g'); const matches = content.match(regex); if (matches) { fileCount += matches.length; content = content.replace(regex, optimizedUrl); } } if (fileCount > 0) { fs.writeFileSync(filePath, content); console.log(`✅ ${file}: ${fileCount} yol güncellendi`); totalReplacements += fileCount; } else { console.log(`⏭️ ${file}: değişiklik yok`); } } console.log(`\n🎉 Toplam ${totalReplacements} resim yolu güncellendi!`);