seo-handler.js
7.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
* seo handler
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2017/12/22
*/
const _ = require('lodash');
const getSeoCheckedParamsName = (sorts, checked) => {
let kd = {};
_.forEach(sorts, val => {
if (val.active) {
kd.sort = val && val.name;
_.forEach(val.childList, sub => {
if (sub.childActive && (!sub.categoryId || sub.categoryId !== val.categoryId)) {
kd.sort = sub && sub.name;
}
});
}
});
checked = checked || [];
_.forEach(checked, ck => {
if (!(ck && ck.itemType)) {
return false;
}
switch (ck && ck.itemType) {
case 'brand':
case 'color':
case 'size':
case 'price':
case 'style':
kd[ck.itemType] = ck.name;
break;
case 'gender':
kd.channel = ck.name === 'GIRLS' ? '女生' : '男生';
break;
default:
if (ck.itemType) {
if (!kd.senior) {
kd.senior = '';
} else {
kd.senior += '、';
}
kd.senior += ck.name;
}
break;
}
});
return kd;
};
const saleDefaultSeoMap = {
vip: {
title: 'VIP会员专享|会员专享|YOHO!BUY有货',
keywords: '会员专享,VIP专享,专享商品',
description: '有货网为您带VIP会员专享精选商品,大量潮流品牌商品,VIP价格优惠幅度大,支持货到付款,让您全面了解VIP会员专享商品价格、品牌、图片、折扣等方面信息,想网购VIP会员专享商品就上有货网!' // eslint-disable-line
},
breakingYards: {
title: '断码商品|断码折扣商品|YOHO!BUY有货',
keywords: '断码商品、断码专区、断码折扣',
description: '有货网为您带断码专区精选商品,大量断码商品,价格优惠幅度大,支持货到付款,让您全面了解潮流断码商品价格、品牌、图片、折扣等方面信息,想网购潮流断码区商品就上有货网!'
},
newSale: {
title: '降价优选商品|潮流降价精品|YOHO!BUY有货',
keywords: '降价优选、降价商品,潮流商品',
description: '有货网为您带来降价优选商品,大量降价折扣优选商品,价格优惠幅度大,质量保证,支持货到付款,让您全面了解降价优选商品价格、品牌、图片、折扣等方面信息,想网购潮流降价商品就上有货网!'
}
};
const getSaleListSeo = (sorts, checked, type) => {
const defaultTdk = saleDefaultSeoMap[type] || {};
const kd = getSeoCheckedParamsName(sorts, checked);
const typeNameMap = {
vip: 'VIP特惠',
breakingYards: '断码',
newSale: '降价'
};
// 无筛选参数时默认tdk
if (_.isEmpty(kd)) {
return defaultTdk;
}
_.forEach(['sort', 'brand', 'color', 'size', 'price', 'channel', 'style', 'senior'], val => {
kd[val] = kd[val] || '';
});
return {
title: `SALE${typeNameMap[type] || ''}超值潮品|${kd.price ? '价格在' : ''}${kd.price}${kd.brand}${kd.channel}${kd.color}${kd.size}${kd.sort}|YOHO!BUY有货`, // eslint-disable-line
keywords: `${kd.size}${kd.color}${kd.brand}${kd.channel}${kd.sort}${kd.style ? ',' : ''}${kd.style}` || defaultTdk.keywords, // eslint-disable-line
description: `超值潮流网购${kd.brand}就上YOHO!BUY有货,有货网销售正品新款${kd.size}${kd.color}${kd.brand}${kd.channel}${kd.sort},全场低至4折,100%品牌正品保证,支持货到付款。` // eslint-disable-line
};
};
const getGlobalListSeo = (sorts, checked) => {
const defaultTdk = {
title: '全球购潮流服装配饰,创意生活用品_男生|女生|潮童服装,鞋履,配饰品牌正品-YOHO!BUY有货',
keywords: '潮流服装配饰,创意生活用品,男生服装配饰,女生服装配饰,潮童服装配饰',
description: '全球购潮流服装配饰及创意生活正品网购!YOHO!BUY有货提供男生、女生、潮童服装配饰。100%品牌正品保证,支持货到付款。'
};
const kd = getSeoCheckedParamsName(sorts, checked);
// 无筛选参数时默认tdk
if (_.isEmpty(kd)) {
return defaultTdk;
}
_.forEach(['sort', 'brand', 'color', 'size', 'price', 'channel', 'style', 'senior'], val => {
kd[val] = kd[val] || '';
});
return {
title: `全球购${kd.price ? '价格在' : ''}${kd.price}${kd.brand}${kd.channel}${kd.color}${kd.size}${kd.sort}|YOHO!BUY有货`, // eslint-disable-line
keywords: `${kd.size}${kd.color}${kd.brand}${kd.channel}${kd.sort}${kd.style ? ',' : ''}${kd.style}` || defaultTdk.keywords, // eslint-disable-line
description: `全球购潮流网购${kd.brand}就上YOHO!BUY有货,有货网销售正品新款${kd.size}${kd.color}${kd.brand}${kd.channel}${kd.sort},全场低至4折,100%品牌正品保证,支持货到付款。` // eslint-disable-line
};
};
const getShopHomeSeo = (shopInfo) => {
let params = {
nameEn: '',
name: ''
};
if (shopInfo) {
Object.assign(params, {
nameEn: _.get(shopInfo, 'brandNameEn', ''),
nameCn: _.get(shopInfo, 'brandNameCn', '')
});
params.name = `${params.nameEn} ${params.nameCn}`;
if (shopInfo.shopName) {
Object.assign(params, {
nameEn: shopInfo.shopName,
name: shopInfo.shopName
});
}
}
return {
title: `${params.nameEn} | ${params.name}品牌旗舰店 | 正品保证, YOHO!BUY 有货`,
keywords: `${params.nameEn}, ${params.name}品牌旗舰店,${params.name}正品`,
description: `有货网${params.nameEn}旗舰店销售${params.name}正品商品,100%质量保证,支持货到付款,想了解${params.name}价格、图片、评价等信息,就上YOHO!BUY 有货中国大型潮流商品购物网站!` // eslint-disable-line
};
};
const getShopListSeo = (sorts, checked, shopInfo) => {
const kd = getSeoCheckedParamsName(sorts, checked);
const defaultTdk = getShopHomeSeo(shopInfo);
// 无筛选参数时返回空对象
if (_.isEmpty(kd)) {
return defaultTdk;
}
_.forEach(['sort', 'brand', 'color', 'size', 'price', 'channel', 'style', 'senior'], val => {
kd[val] = kd[val] || '';
});
let shopName = shopInfo.shopName || `${shopInfo.brandNameEn} ${shopInfo.brandNameCn}`;
shopName += shopName ? '品牌旗舰店' : '';
return {
title: `${shopName}|${kd.price ? '价格在' : ''}${kd.price}${kd.brand}${kd.channel}${kd.color}${kd.size}${kd.sort}|YOHO!BUY有货`, // eslint-disable-line
keywords: `${kd.size}${kd.color}${kd.brand}${kd.channel}${kd.sort}${kd.style ? ',' : ''}${kd.style}` || defaultTdk.keywords, // eslint-disable-line
description: `潮流网购${kd.brand}就上YOHO!BUY有货${shopName},有货网销售正品新款${kd.size}${kd.color}${kd.brand}${kd.channel}${kd.sort},全场低至4折,100%品牌正品保证,支持货到付款。` // eslint-disable-line
};
};
module.exports = {
getSeoCheckedParamsName,
getSaleListSeo,
getGlobalListSeo,
getShopHomeSeo,
getShopListSeo,
};