seo-handler.js
11.8 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/**
* seo handler
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2017/12/22
*/
const _ = require('lodash');
const NOW_YEAR = new Date().getFullYear();
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 listDefaultTdk = {
title: '【潮流商品】_潮流男装_潮流女装_潮流童装-YOHO!BUY 有货',
keywords: '潮流男装,潮流女装,潮流童装',
description: '潮流网购就上YOHO!BUY有货,有货网潮流商品专卖店提供潮流商品品牌、潮流商品价格、潮流商品图片等信息。销售正品新款潮流男装、潮流女装、潮流童装,全场低至4折,★全场品牌正品保证,支持货到付款!★' // eslint-disable-line
};
/**
* 列表页seo
* @param sorts
* @param checked
* @returns {{title: string, keywords: string, description: string}}
*/
const getListSeo = (sorts, checked, extend = {}) => {
let {brand, channel, color, style, sort} = Object.assign(getSeoCheckedParamsName(sorts, checked), extend);
if (brand && _.indexOf(brand, '、') > -1) {
brand = '';
}
let name = _.compact([brand, channel, color, style, sort]).join('');
if (!name) {
return listDefaultTdk;
}
let desc = sort ? `${sort}:潮流网购就上YOHO!BUY有货,有货网${sort}专卖店提供${sort}品牌、${sort}价格、${sort}图片等信息。销售正品新款${sort},全场低至4折,★全场品牌正品保证,支持货到付款!★` : listDefaultTdk.description; // eslint-disable-line
if (name === sort) {
return {
title: `【${sort}】_${sort}品牌_${sort}价格_${sort}图片-YOHO!BUY 有货`,
keywords: `${sort},${sort}品牌,${sort}价格,${sort}图片`,
description: desc
};
} else {
return {
title: `【${name}】_价格,图片,款式-YOHO!BUY 有货`,
keywords: name,
description: desc
};
}
};
/**
* 新品到页 seo
* @param sorts
* @param checked
* @returns {{title: string, keywords: string, description: string}}
*/
const getNewListSeo = (sorts, checked) => {
const tdk = {
title: `【潮流新品】_引领潮流_${NOW_YEAR}时尚潮流新品-YOHO!BUY 有货`,
keywords: `潮流新品.引领潮流,${NOW_YEAR}时尚潮流新品`,
description: `【潮流新品】,${NOW_YEAR}时尚潮流新品,潮流网购就上YOHO!BUY有货,有货网销售正品新款,全场低至4折,★全场品牌正品保证,支持货到付款!★`
};
const kd = getSeoCheckedParamsName(sorts, checked);
let name = _.compact([kd.price ? `价格在${kd.price}` : '', kd.brand,
kd.channel, kd.color, kd.size, kd.sort]).join('_');
if (name) {
tdk.title = `【潮流新品】_${name}-YOHO!BUY 有货`;
}
return tdk;
};
/**
* sale列表页seo
* @param sorts
* @param checked
* @param type
* @returns {{title: string, keywords: string, description: string}}
*/
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
};
};
/**
* 全球购列表页seo
* @param sorts
* @param checked
* @returns {{title: string, keywords: string, description: string}}
*/
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
};
};
/**
* 店铺首页seo
* @param shopInfo
* @returns {{title: string, keywords: string, description: string}}
*/
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}品牌官方旗舰店`,
description: `潮流网购就上YOHO!BUY有货官网,${params.nameEn}品牌官方旗舰店提供${params.name}品牌商品价格、图片、款式等信息,销售${params.name}品牌正品商品,全场低至4折,★品牌正品保证,支持货到付款!★` // eslint-disable-line
};
};
/**
* 店铺列表页seo
* @param sorts
* @param checked
* @param shopInfo
* @returns {{title: string, keywords: string, description: string}}
*/
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
};
};
/**
* 商品详情页seo
* @param goodsInfo
* @param navs
* @returns {{title: string, keywords: string, description: string}}
*/
const getProductDetailSeo = (goodsInfo, navs) => {
let brandName = _.get(goodsInfo, 'data.brand_info.brand_name', '');
let sortName = _.get(navs, '[1].name', '');
let productName = _.get(goodsInfo, 'data.product_name', '');
let priceName = _.get(goodsInfo, 'data.format_sales_price');
return {
title: `${productName}_${brandName}${sortName}-YOHO!BUY 有货`,
keywords: `${brandName}${sortName},${brandName}${sortName}价格,${brandName}${sortName}图片`,
description: `${productName},有货网仅售${priceName}元,购买${brandName +
sortName},了解${brandName + sortName}商品信息就上有货网!`
};
};
const getHotKeywordsSeo = (keyword, num) => {
return {
title: `${keyword}_${keyword}【图片,新款,价格,折扣,搭配】-YOHO!BUY有货`,
keywords: keyword,
description: `YOHO!BUY 有货网是国内专业的${keyword}网上潮流购物商城,为您找到${num}条${keyword}产品的品牌、图片、款式、价格、折扣等信息。买正品${keyword},就上YOHO!BUY有货!` // eslint-disable-line
};
};
module.exports = {
getSeoCheckedParamsName,
getListSeo,
getNewListSeo,
getSaleListSeo,
getGlobalListSeo,
getShopHomeSeo,
getShopListSeo,
getProductDetailSeo,
getHotKeywordsSeo
};