Fix catalog parser for anchor attribute order
This commit is contained in:
@@ -35,14 +35,18 @@ function skuFromHref(href, index) {
|
||||
|
||||
function parseCatalogCards(html) {
|
||||
const cards = [];
|
||||
const cardRegex =
|
||||
/<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;
|
||||
const cardRegex = /<a([^>]*)class="[^"]*product-card[^"]*"([^>]*)>([\s\S]*?)<\/a>/g;
|
||||
|
||||
let match;
|
||||
while ((match = cardRegex.exec(html)) !== null) {
|
||||
const href = match[1];
|
||||
const title = normalizeText(match[2]);
|
||||
const type = normalizeText(match[3]);
|
||||
const attrs = `${match[1]} ${match[2]}`;
|
||||
const body = 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) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user