const { matchAttendeeToPersons, loadPersons } = require('./person-matcher.js'); function matchSpeakers(speakers, personsList) { const persons = personsList || loadPersons(); const map = new Map(); for (const speaker of speakers) { const attendee = { name: speaker.name, email: speaker.email || '' }; const match = matchAttendeeToPersons(attendee, persons); if (match.matched) { const personName = match.file.replace('.md', ''); map.set(speaker.name, `[[00 Kontext/Personen/${personName}]]`); } else { map.set(speaker.name, null); } } return map; } function escapeRegex(s) { return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); } function replaceSpeakerNames(text, map) { const entries = [...map.entries()] .filter(([_, link]) => link !== null) .sort((a, b) => b[0].length - a[0].length); if (entries.length === 0) return text; const pattern = entries.map(([name]) => escapeRegex(name)).join('|'); const re = new RegExp(pattern, 'g'); return text.replace(re, (match) => { return map.get(match) || match; }); } module.exports = { matchSpeakers, replaceSpeakerNames };