${escapeHTML(p.title)}
${renderPill('section', state.sectionTitles[p.section] || p.section)} ${programPills}${formatDate(p.date)}
${excerpt}
function renderPill(type, value, extra = '') {
return `${escapeHTML(value)}`;
}
function renderCard(p, matches = []) {
const coverStyle = p.cover ? `style="background-image:url(${p.cover}); background-size:cover;"` : '';
let excerpt = p.excerpt;
if (matches.length) {
const terms = new Set(matches.flatMap(m => m.indices.map(i => excerpt.slice(i[0], i[1] + 1))));
terms.forEach(t => {
excerpt = excerpt.replace(new RegExp(escapeRegExp(t), 'gi'), `${t}`);
});
}
const programPills = (p.programs || []).map(pr => renderPill('program', state.programTitles[pr] || pr)).join('');
return ` ${formatDate(p.date)} ${excerpt}${escapeHTML(p.title)}
${renderPill('section', state.sectionTitles[p.section] || p.section)}
${programPills}