feat(seo): enrich Torob product title, subtitle and technical specs for optimal search indexation
Deploy Canina / deploy (push) Successful in 2m22s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s

This commit is contained in:
parsa aghaei committed 2026-09-02 09:30:33 +03:30
1 parent 88060431bb
commit 382ebc0ce6
16 files changed
+151527 -5915

No files matched your search

+112 -5
View File
@@ -2,6 +2,99 @@ import { Controller, Get, Query } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { PrismaService } from '../prisma/prisma.service';
function buildTorobProductTitle(product: {
nameFa?: string | null;
nameEn?: string | null;
packageSize?: unknown;
unit?: string | null;
suitableFor?: string | null;
}): string {
const nameFa = (product.nameFa || '').trim();
let nameEn = (product.nameEn || '').trim();
// Clean brand duplicate if nameEn already starts with Canina
if (/^Canina\b/i.test(nameEn)) {
nameEn = nameEn.replace(/^Canina\s*[-–:]*\s*/i, '').trim();
}
// Package size & unit
let sizePart = '';
const numSize = Number(product.packageSize);
const unit = (product.unit || '').trim();
if (numSize && numSize > 0) {
sizePart = unit ? `${numSize} ${unit}` : `${numSize}`;
}
// Suitable for pet
let petPart = '';
if (product.suitableFor) {
const pet = product.suitableFor.trim();
if (pet === 'هر دو' || pet === 'سگ و گربه' || pet === 'سگ، گربه') {
petPart = 'مناسب سگ و گربه';
} else if (pet) {
petPart = `مناسب ${pet}`;
}
}
const parts: string[] = [];
if (nameFa) parts.push(nameFa);
// Brand part
if (!nameFa.includes('کنینا') && !nameFa.includes('Canina')) {
parts.push('برند کنینا Canina');
} else if (!nameFa.includes('Canina')) {
parts.push('Canina');
}
if (nameEn && nameEn.toLowerCase() !== nameFa.toLowerCase()) {
parts.push(nameEn);
}
if (sizePart && !nameFa.includes(sizePart) && !nameEn.includes(sizePart)) {
parts.push(sizePart);
}
if (petPart && !nameFa.includes(petPart)) {
parts.push(petPart);
}
return parts.join(' ').replace(/\s+/g, ' ').trim();
}
function buildTorobProductSpec(product: {
packageSize?: unknown;
unit?: string | null;
suitableFor?: string | null;
artNo?: string | null;
category?: { name?: string } | null;
}): Record<string, string> {
const spec: Record<string, string> = {
'برند': 'کنینا (Canina Pharma Germany)',
'کشور سازنده': 'آلمان',
'ضمانت': 'اصالت ۱۰۰٪ کالای آلمانی و سلامت فیزیکی',
};
if (product.suitableFor) {
spec['گونه هدف'] = product.suitableFor === 'هر دو' ? 'سگ و گربه' : product.suitableFor;
}
const numSize = Number(product.packageSize);
const unit = (product.unit || '').trim();
if (numSize && numSize > 0) {
spec['حجم / وزن / تعداد'] = unit ? `${numSize} ${unit}` : `${numSize}`;
}
if (product.artNo) {
spec['کد محصول (Art.No)'] = product.artNo;
}
if (product.category?.name) {
spec['دسته دارویی و درمانی'] = product.category.name;
}
return spec;
}
@ApiTags('Torob Integration - وب‌سرویس اتصال به ترب')
@Controller('torob')
export class TorobController {
@@ -28,6 +121,9 @@ export class TorobController {
where: whereCondition,
skip: (page - 1) * pageSize,
take: pageSize,
include: {
category: { select: { name: true } },
},
orderBy: { createdAt: 'desc' },
}),
]);
@@ -38,10 +134,20 @@ export class TorobController {
const slug = product.slug || product.artNo || product.id;
const pageUrl = `${baseUrl}/shop/${slug}`;
const productId = String(product.artNo || product.id || slug);
const nameFa = product.nameFa || '';
const nameEn = product.nameEn || '';
const title = nameEn ? `${nameFa} (${nameEn})` : nameFa;
const title = buildTorobProductTitle(product);
const spec = buildTorobProductSpec(product);
// Construct pure English subtitle
const rawEn = (product.nameEn || '').trim();
const numSize = Number(product.packageSize);
const unit = (product.unit || '').trim();
const sizeStr = numSize && numSize > 0 ? (unit ? `${numSize} ${unit}` : `${numSize}`) : '';
let subtitle = rawEn.startsWith('Canina') ? rawEn : `Canina ${rawEn}`.trim();
if (sizeStr && !subtitle.includes(sizeStr)) {
subtitle = `${subtitle} - ${sizeStr}`;
}
const rawImage = product.ogImage || product.imageUrl || '';
let imageLink = '';
if (rawImage) {
@@ -66,14 +172,15 @@ export class TorobController {
product_id: productId,
page_unique_code: productId,
title,
subtitle: nameEn || product.scientificTagline || '',
subtitle,
page_url: pageUrl,
price,
old_price: oldPrice,
availability: isInStock ? 'instock' : 'outofstock',
image_link: imageLink,
guarantee: 'ضمانت اصالت ۱۰۰٪ کمپانی Canina آلمان و اصالت کالا',
category_name: product.categorySlug || 'مکمل حیوانات خانگی',
category_name: product.category?.name || product.categorySlug || 'مکمل حیوانات خانگی',
spec,
};
});