Fix catalog parser for anchor attribute order
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user