bep40 commited on
Commit
45a1849
·
verified ·
1 Parent(s): 5d47bae

url-product: TDZ fix, full desc + specs

Browse files
Files changed (1) hide show
  1. index.ts +2 -3
index.ts CHANGED
@@ -1496,7 +1496,7 @@ const server = Bun.serve({
1496
  const out: Record<string, any> = { link: u.href };
1497
 
1498
  // ── JSON-LD (Product blocks) ──
1499
- let ldProduct: any = null, ldDesc = "", ldPrice = 0;
1500
  const ldRe = /<script[^>]*type=["']application\/ld\+json["'][^>]*>([\s\S]*?)<\/script>/g;
1501
  let lm: RegExpExecArray | null;
1502
  while ((lm = ldRe.exec(html))) {
@@ -1536,8 +1536,7 @@ const server = Bun.serve({
1536
  if (!name && title) name = title.split(/[|–—-]/)[0].trim();
1537
 
1538
  // ── sku / model: prefer URL slug token (MS7743SI) then HTML "Mã sản phẩm" then JSON-LD sku ──
1539
- // JSON-LD sku may come later (declared before the JSON-LD block is scanned).
1540
- let skuLD = "";
1541
  const slugToken = (u.pathname.split("/").filter(Boolean).pop() || "").match(/[A-Z]{2,}\d{3,}[A-Z]*/i);
1542
  let sku = slugToken ? slugToken[0].toUpperCase() : "";
1543
  const msku = html.match(/Mã (?:sản phẩm|SP)[^>]*>?\s*([^<]{2,30})</i) || html.match(/(?:data-sku|itemprop="sku")[^>]*["']([A-Z0-9-]{3,30})["']/i);
 
1496
  const out: Record<string, any> = { link: u.href };
1497
 
1498
  // ── JSON-LD (Product blocks) ──
1499
+ let ldProduct: any = null, ldDesc = "", ldPrice = 0, skuLD = "";
1500
  const ldRe = /<script[^>]*type=["']application\/ld\+json["'][^>]*>([\s\S]*?)<\/script>/g;
1501
  let lm: RegExpExecArray | null;
1502
  while ((lm = ldRe.exec(html))) {
 
1536
  if (!name && title) name = title.split(/[|–—-]/)[0].trim();
1537
 
1538
  // ── sku / model: prefer URL slug token (MS7743SI) then HTML "Mã sản phẩm" then JSON-LD sku ──
1539
+ // skuLD is declared above next to the other JSON-LD lets.
 
1540
  const slugToken = (u.pathname.split("/").filter(Boolean).pop() || "").match(/[A-Z]{2,}\d{3,}[A-Z]*/i);
1541
  let sku = slugToken ? slugToken[0].toUpperCase() : "";
1542
  const msku = html.match(/Mã (?:sản phẩm|SP)[^>]*>?\s*([^<]{2,30})</i) || html.match(/(?:data-sku|itemprop="sku")[^>]*["']([A-Z0-9-]{3,30})["']/i);