const fs = require('fs'); let code = fs.readFileSync('src/components/SmartSearchBar.tsx', 'utf8'); const regexMatchText = `const numericMatch = cleanQuery.match(/\\d+/);`; const newMatchLogic = ` const numericMatch = cleanQuery.match(/\\d+/); // Parse "samedi", "dimanche" etc. let searchDateStr = ''; const days = ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi']; const foundDay = days.find(d => cleanQuery.toLowerCase().includes(d)); if (foundDay) { const today = new Date(); const currentDay = today.getDay(); const targetDay = days.indexOf(foundDay); let diff = targetDay - currentDay; // If the day is in the past (e.g. today is Tuesday, user searches for "samedi"), it might mean last Saturday or next Saturday. // Let's default to the closest one in the future, or if it's "de samedi" and today is Monday, maybe it means 2 days ago? // Let's just find the closest date (past or future within 7 days) if (diff > 3) diff -= 7; else if (diff < -3) diff += 7; const targetDate = new Date(); targetDate.setDate(today.getDate() + diff); const dd = String(targetDate.getDate()).padStart(2, '0'); const mm = String(targetDate.getMonth() + 1).padStart(2, '0'); const yyyy = targetDate.getFullYear(); searchDateStr = \`?date=\${dd}/\${mm}/\${yyyy}\`; } `; code = code.replace(regexMatchText, newMatchLogic); code = code.replace(/url: getRegionPath\(\`\/horaires\/train\/\$\{t\.numero_train\}\`\)/g, "url: getRegionPath(`/horaires/train/${t.numero_train}`) + searchDateStr"); code = code.replace(/url: getRegionPath\(\`\/horaires\/train\/\$\{numStr\}\`\)/g, "url: getRegionPath(`/horaires/train/${numStr}`) + searchDateStr"); fs.writeFileSync('src/components/SmartSearchBar.tsx', code);