fix(wiki): synchronize 30 canonical ingredients in static data and ensure immediate product matching with clean title formatting
Deploy Canina / deploy (push) Failing after 27s
Deploy Canina / deploy (push) Failing after 27s
This commit is contained in:
1 parent
d8fc57c23d
commit
30670d7f6d
10 files changed
+44416
-44059
No files matched your search
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { Product, IngredientInfo } from "../lib/data/products";
|
||||
import { Product, IngredientInfo, PRODUCTS, INGREDIENTS_WIKI } from "../lib/data/products";
|
||||
import { motion } from "motion/react";
|
||||
import { FlaskConical, CheckCircle2, ChevronRight, ChevronLeft, Beaker, Search } from "lucide-react";
|
||||
import { productService } from "../lib/services/productService";
|
||||
@@ -18,72 +18,84 @@ const INGREDIENT_MATCH_KEYWORDS: Record<string, string[]> = {
|
||||
"hydroxyapatite": ["هیدروکسی", "آپاتیت", "hydroxyapatite", "canhydrox"],
|
||||
"collagen": ["کلاژن", "collagen", "flexan"],
|
||||
"colostrum": ["آغوز", "colostrum", "immun-booster", "ایمون بوستر"],
|
||||
"silver": ["نقره", "میکروسیلور", "silver", "zahngel", "ژل دندان"],
|
||||
"peat-extract": ["پیت", "moor", "moortranke", "هومیک", "عصاره پیت"],
|
||||
"silver": ["نقره", "میکروسیلور", "silver", "zahngel", "ژل دندان", "دندان"],
|
||||
"peat-extract": ["پیت", "moor", "moortranke", "هومیک", "عصاره پیت", "گوارش"],
|
||||
"salmon-oil": ["سالمون", "ماهی", "salmon", "lachs", "امگا", "marine", "welpenmilch", "katzenmilch"],
|
||||
"black-cumin": ["سیاه دانه", "زیره", "cumin", "schwarz", "kummel"],
|
||||
"black-cumin": ["سیاه دانه", "سیاهدانه", "زیره", "cumin", "schwarz", "kummel"],
|
||||
"eggshell": ["پوسته", "تخم مرغ", "تخممرغ", "eggshell", "eierschalen"],
|
||||
"biotin": ["بیوتین", "biotin", "vitamin h", "ویتامین h"],
|
||||
"taurin": ["تورین", "taurin", "taurine", "katzenmilch"],
|
||||
"seaweed": ["جلبک", "seaweed", "seealgen", "seelgen", "ascophyllum", "canhydrox"],
|
||||
"l-carnitine": ["کارنیتین", "carnitine", "herz-vital", "هرز ویتال"],
|
||||
"hawthorn": ["زالزالک", "hawthorn", "crataegus", "herz-vital", "هرز ویتال"],
|
||||
"brewer-yeast": ["مخمر", "yeast", "hefe", "b-complex", "canhydrox", "mineral-tabs", "vitamin-tabs", "taurin"],
|
||||
"l-carnitine": ["کارنیتین", "carnitine", "herz-vital", "هرز ویتال", "قلب"],
|
||||
"hawthorn": ["زالزالک", "hawthorn", "crataegus", "herz-vital", "هرز ویتال", "قلب"],
|
||||
"brewer-yeast": ["مخمر", "yeast", "hefe", "b-complex", "canhydrox", "mineral-tabs", "vitamin-tabs", "taurin", "hefe-tabletten"],
|
||||
"bovine-blood": ["خون", "rinderblut", "blood", "آهن", "هموگلوبین", "سرم"],
|
||||
"bovine-fat": ["چربی", "rinderfett", "fat", "کالری", "گوشت گاو", "energy-gel", "immun-booster", "katzenmilch", "welpenmilch"],
|
||||
"willow-bark": ["بید", "willow", "salix", "arthro", "آرترو"],
|
||||
"ginger": ["زنجبیل", "ginger", "zingiber", "arthro", "آرترو"],
|
||||
"hyaluronic": ["هیالورونات", "hyaluron", "augenpflege", "چشم"],
|
||||
"calendula-sea-buckthorn": ["کالاندولا", "سنجد", "خولان", "pfotenpflege", "پنجه", "همیشهبهار"],
|
||||
"dodecanoic": ["دودکانوئیک", "مارگوسا", "insect", "کک", "کنه", "حشرات"],
|
||||
"calcium-carbonate": ["کربنات کلسیم", "calcium-carbonat", "mineral-tabs", "welpenkalk", "gag", "vitamin-tabs", "ballaststoff"],
|
||||
"calendula-sea-buckthorn": ["کالاندولا", "سنجد", "خولان", "pfotenpflege", "پنجه", "همیشهبهار", "پوست"],
|
||||
"dodecanoic": ["دودکانوئیک", "مارگوسا", "insect", "کک", "کنه", "حشرات", "ضد انگل", "پپت-پروتکت", "pet-protect", "اسپری"],
|
||||
"calcium-carbonate": ["کربنات کلسیم", "کلسیم", "calcium-carbonat", "mineral-tabs", "welpenkalk", "gag", "vitamin-tabs", "ballaststoff"],
|
||||
"vitamin-c": ["ویتامین c", "ویتامین سی", "ascorbic", "vitamin-c", "zahngel", "canhydrox"],
|
||||
"vitamin-e": ["ویتامین e", "ویتامین ای", "tocopherol", "vitamin-e", "canhydrox", "immun-booster", "energy-gel", "gag", "arthro"],
|
||||
"vitamin-d3": ["ویتامین d3", "ویتامین دی", "cholecalciferol", "d3", "immun-booster", "mineral-tabs", "vitamin-tabs"],
|
||||
"dextrose": ["دکستروز", "dextrose", "گلوکز", "biotin-tabs", "herz-vital"],
|
||||
"marine-oils": ["گردو", "آرگان", "گل رز", "marine-ol", "olmischung", "روغن دریایی"],
|
||||
"vitamin-d3": ["ویتامین d3", "ویتامین دی", "cholecalciferol", "d3", "immun-booster", "mineral-tabs", "vitamin-tabs", "welpenmilch"],
|
||||
"dextrose": ["دکستروز", "dextrose", "گلوکز", "biotin-tabs", "herz-vital", "energy-gel"],
|
||||
"marine-oils": ["گردو", "آرگان", "گل رز", "marine-ol", "olmischung", "روغن دریایی", "روغن"],
|
||||
"apple-fiber": ["سیب", "پکتین", "فیبر", "ballaststoff", "fiber", "یونجه", "هویج", "نخود"],
|
||||
"zinc": ["روی", "zinc", "کلات", "arthro", "seealgen"]
|
||||
"zinc": ["روی", "zinc", "کلات", "arthro", "seealgen", "biotin", "mineral-tabs"]
|
||||
};
|
||||
|
||||
// Formatter to prevent duplicate English names like "آغوز (Colostrum) (Colostrum)"
|
||||
function formatIngredientDisplayName(item: Ingredient): string {
|
||||
const cleanNameFa = (item.nameFa || '').replace(/\s*\([^)]*\)\s*/g, '').trim();
|
||||
const subName = (item.scientificName || item.nameEn || '').trim();
|
||||
function formatIngredientDisplayName(item: { nameFa?: string; scientificName?: string; nameEn?: string; name?: string; slug?: string }): string {
|
||||
const rawName = item.nameFa || item.name || '';
|
||||
const cleanFa = rawName.replace(/\s*\([^)]*\)\s*/g, ' ').replace(/\s+/g, ' ').trim();
|
||||
const sub = (item.scientificName || item.nameEn || '').replace(/\s*\([^)]*\)\s*/g, ' ').replace(/\s+/g, ' ').trim();
|
||||
|
||||
if (cleanNameFa && subName && !cleanNameFa.toLowerCase().includes(subName.toLowerCase())) {
|
||||
return `${cleanNameFa} (${subName})`;
|
||||
if (!cleanFa) return sub || rawName || item.slug || '';
|
||||
if (!sub || cleanFa.toLowerCase() === sub.toLowerCase() || /[\u0600-\u06FF]/.test(sub)) {
|
||||
return cleanFa;
|
||||
}
|
||||
return item.nameFa || item.nameEn || item.slug;
|
||||
|
||||
return `${cleanFa} (${sub})`;
|
||||
}
|
||||
|
||||
export default function IngredientWiki() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const termParam = searchParams.get('term');
|
||||
const [ingredientsWiki, setIngredientsWiki] = useState<IngredientInfo[]>([]);
|
||||
const [products, setProducts] = useState<Product[]>([]);
|
||||
const [ingredientsWiki, setIngredientsWiki] = useState<IngredientInfo[]>(INGREDIENTS_WIKI);
|
||||
const [products, setProducts] = useState<Product[]>(PRODUCTS);
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
productService.getProducts({ limit: 999 }).then(res => setProducts(res.data));
|
||||
productService.getProducts({ limit: 999 })
|
||||
.then(res => {
|
||||
if (res?.data && res.data.length > 0) {
|
||||
setProducts(res.data);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.warn('[IngredientWiki] Using static fallback products:', err);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
api.get('/ingredients')
|
||||
.then(res => {
|
||||
const rawList = Array.isArray(res.data) ? res.data : (res.data?.data || []);
|
||||
const apiList: IngredientInfo[] = rawList.map((item: Ingredient) => ({
|
||||
id: item.slug || item.id,
|
||||
name: formatIngredientDisplayName(item),
|
||||
description: item.description || '',
|
||||
benefits: Array.isArray(item.benefits) ? item.benefits : []
|
||||
}));
|
||||
setIngredientsWiki(apiList);
|
||||
if (rawList.length > 0) {
|
||||
const apiList: IngredientInfo[] = rawList.map((item: Ingredient) => ({
|
||||
id: item.slug || item.id,
|
||||
name: formatIngredientDisplayName(item),
|
||||
description: item.description || '',
|
||||
benefits: Array.isArray(item.benefits) ? item.benefits : []
|
||||
}));
|
||||
setIngredientsWiki(apiList);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('[IngredientWiki] Failed to fetch ingredients from API:', err);
|
||||
setIngredientsWiki([]);
|
||||
console.warn('[IngredientWiki] Using static INGREDIENTS_WIKI fallback:', err);
|
||||
});
|
||||
}, []);
|
||||
|
||||
@@ -103,24 +115,30 @@ export default function IngredientWiki() {
|
||||
// Product matcher for each ingredient
|
||||
const getProductsForIngredient = useMemo(() => {
|
||||
return (ingId: string, ingName: string) => {
|
||||
const cleanSlug = ingId.replace(/-/g, ' ').toLowerCase();
|
||||
const cleanFa = ingName.replace(/\s*\([^)]*\)\s*/g, '').trim().toLowerCase();
|
||||
const cleanSlug = (ingId || '').replace(/-/g, ' ').toLowerCase();
|
||||
const cleanFa = (ingName || '').replace(/\s*\([^)]*\)\s*/g, ' ').trim().toLowerCase();
|
||||
const keywords = INGREDIENT_MATCH_KEYWORDS[ingId] || [];
|
||||
|
||||
return products.filter(p => {
|
||||
const pText = [
|
||||
p.name || '',
|
||||
p.nameFa || '',
|
||||
p.nameEn || '',
|
||||
p.scientificTagline || '',
|
||||
p.slug || '',
|
||||
p.id || '',
|
||||
p.description || '',
|
||||
p.shortDescription || '',
|
||||
p.category || '',
|
||||
p.categorySlug || '',
|
||||
...(p.main_ingredients || []),
|
||||
...(p.benefitsList || []),
|
||||
...(p.keyBenefits?.map(k => `${k.title} ${k.description}`) || []),
|
||||
(p as any).ingredients || ''
|
||||
].join(' ').toLowerCase();
|
||||
|
||||
if (pText.includes(cleanFa) || pText.includes(cleanSlug)) {
|
||||
return true;
|
||||
}
|
||||
if (cleanFa && pText.includes(cleanFa)) return true;
|
||||
if (cleanSlug && pText.includes(cleanSlug)) return true;
|
||||
|
||||
return keywords.some(kw => pText.includes(kw.toLowerCase()));
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user