const months = [ "январ", "феврал", "март", "апрел", "ма", "июн", "июл", "август", "сентябр", "октябр", "ноябр", "декабр", ]; function russianDates(text) { const dates = []; for (const match of text.matchAll(/(\d{1,2})\s+([а-яё]+)\s+(20\d{2})/gi)) { const month = months.findIndex((prefix) => match[2].toLowerCase().startsWith(prefix), ); if (month >= 0) dates.push( `${match[3]}-${String(month + 1).padStart(2, "0")}-${match[1].padStart(2, "0")}`, ); } return dates; } function organizerUrl(value) { try { const url = new URL(value.replace(/&/g, "&")); if ( !["https:", "http:"].includes(url.protocol) || url.username || url.password || !/^[a-z0-9-]+(?:\.[a-z0-9-]+)+\.[a-z][a-z0-9-]*$|^[a-z0-9-]+\.[a-z][a-z0-9-]*$/i.test( url.hostname, ) ) return null; if (/\.(?:local|localhost|internal|test|invalid)$/i.test(url.hostname)) return null; return url.href; } catch { return null; } } // The Crocus index is an accordion of exhibition records. Its detail_theme links are topic filters. export function crocusCalendar(body, day, clean) { const blocks = body .split(/
]*class=["']leftimg-exhibition-about["'][^>]*>([\s\S]*?)<\/p>/i,
)?.[1];
if (!label) continue;
const title = clean(label.match(/]*>([\s\S]*?)<\/span>/i)?.[1]);
const dates = russianDates(
clean(label.match(/]*>([\s\S]*?)<\/b>/i)?.[1]),
);
if (!title || !dates.length || day < dates[0] || day > dates.at(-1))
continue;
const address = block.match(
/\s*Сайт:\s*<\/strong>\s*]*href\s*=\s*["']([^"']+)["']/i,
)?.[1];
const url = address && organizerUrl(address);
if (!url) continue;
const description = clean(label.match(/]*>([\s\S]*?)<\/em>/i)?.[1]);
const venue = clean(
block.match(
/Место проведения:\s*<\/b>[\s\S]{0,150}?