Fix catalog parser for anchor attribute order

This commit is contained in:
Ruslan Bakiev
2026-03-31 12:31:45 +07:00
parent 705d76c597
commit f135c12785

View File

@@ -35,14 +35,18 @@ function skuFromHref(href, index) {
function parseCatalogCards(html) { function parseCatalogCards(html) {
const cards = []; const cards = [];
const cardRegex = const cardRegex = /<a([^>]*)class="[^"]*product-card[^"]*"([^>]*)>([\s\S]*?)<\/a>/g;
/<a[^>]*class="[^"]*product-card[^"]*"[^>]*href="([^"]+)"[^>]*>[\s\S]*?<div class="product-card__title">([\s\S]*?)<\/div>\s*<div class="product-card__type">([\s\S]*?)<\/div>/g;
let match; let match;
while ((match = cardRegex.exec(html)) !== null) { while ((match = cardRegex.exec(html)) !== null) {
const href = match[1]; const attrs = `${match[1]} ${match[2]}`;
const title = normalizeText(match[2]); const body = match[3];
const type = normalizeText(match[3]); const hrefMatch = attrs.match(/href="([^"]+)"/);
const titleMatch = body.match(/<div class="product-card__title">([\s\S]*?)<\/div>/);
const typeMatch = body.match(/<div class="product-card__type">([\s\S]*?)<\/div>/);
const href = hrefMatch?.[1] ?? '';
const title = normalizeText(titleMatch?.[1] ?? '');
const type = normalizeText(typeMatch?.[1] ?? '');
if (!title) { if (!title) {
continue; continue;
} }