bep40 commited on
Commit
b4f2f25
·
verified ·
1 Parent(s): 08d470e

Fix og:image for bigsale SEO links — load from catalog

Browse files
Files changed (1) hide show
  1. index.ts +8 -1
index.ts CHANGED
@@ -260,7 +260,14 @@ async function serveProductOG(req: Request): Promise<Response> {
260
  if (bsProd) {
261
  const bsName = esc(bsProd.name || bsProd.code || "Sản phẩm BIG SALE");
262
  const bsPrice = Number(String(bsProd.bigsale || "").replace(/\./g, "")) || 0;
263
- const bsImgRaw = bsProd.image || "";
 
 
 
 
 
 
 
264
  const bsImg = bsImgRaw ? escURL(bsImgRaw) : fallbackImg;
265
  const ogTitle = "🔥 BIG SALE: " + bsName + (bsPrice > 0 ? " - " + Number(bsPrice).toLocaleString("vi-VN") + "₫" : "") + " | V.AI STUDIO";
266
  const ogDesc = (bsPrice > 0 ? "Giá BIG SALE " + bsName + " chỉ còn " + Number(bsPrice).toLocaleString("vi-VN") + "₫" : "Chương trình BIG SALE V.AI STUDIO") + " | Giảm " + esc("-" + (bsProd.discount || "0%"));
 
260
  if (bsProd) {
261
  const bsName = esc(bsProd.name || bsProd.code || "Sản phẩm BIG SALE");
262
  const bsPrice = Number(String(bsProd.bigsale || "").replace(/\./g, "")) || 0;
263
+ let bsImgRaw = bsProd.image || "";
264
+ if (!bsImgRaw) {
265
+ const codeNorm = String(bsProd.code || "").trim().toUpperCase().replace(/\s+/g, " ");
266
+ if (typeof allProducts !== "undefined" && Array.isArray(allProducts)) {
267
+ const catProd = allProducts.find(function(x: any){ const sku=String(x.sku||x.model||x.slug||"").trim().toUpperCase().replace(/\s+/g," "); return sku===codeNorm || String(x.title_clean||x.name||"").toUpperCase().replace(/\s+/g," ").indexOf(codeNorm)>=0; });
268
+ if (catProd && catProd.image) bsImgRaw = catProd.image;
269
+ }
270
+ }
271
  const bsImg = bsImgRaw ? escURL(bsImgRaw) : fallbackImg;
272
  const ogTitle = "🔥 BIG SALE: " + bsName + (bsPrice > 0 ? " - " + Number(bsPrice).toLocaleString("vi-VN") + "₫" : "") + " | V.AI STUDIO";
273
  const ogDesc = (bsPrice > 0 ? "Giá BIG SALE " + bsName + " chỉ còn " + Number(bsPrice).toLocaleString("vi-VN") + "₫" : "Chương trình BIG SALE V.AI STUDIO") + " | Giảm " + esc("-" + (bsProd.discount || "0%"));