guang-helper.js
2.9 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
/**
* 逛 model
* @author: lcy<chuanyang.liu@yoho.cn>
* @date: 2016/09/06
*/
'use strict';
const md5 = require('md5');
const requestIp = require('request-ip');
const _ = require('lodash');
const helpers = global.yoho.helpers;
/* COOKIE标识访问的是男生频道 */
// const COOKIE_NAME_BOYS = 'boys';
// const COOKIE_DOMAIN = '.yohobuy.com';
const getGenderByCookie = (req) => {
let gender = null;
let channel = req.yoho.channel;
switch (channel) {
case 'boys':
{
gender = '1,3';
break;
}
case 'girls':
{
gender = '2,3';
break;
}
default:
{
gender = '1,2,3';
}
}
return gender;
};
/**
* 获取客户端唯一标识
*
* @return string
*/
const getUdid = (req, res) => {
let udid = req.cookies.udid;
if (!udid) {
udid = md5(req.ip || requestIp.getClientIp(req));
if (res && res.cookie) {
res.cookie('udid', udid);
}
}
return udid;
};
/**
* 获得文章 url
* @param type string url 后台返回的url
* @param type id 产品编号
* @return type url
*/
const getArticleUrl = (url, id) => {
/* 格式由url:{url:'aaa'} 更改为 url: 'aaa'
try {
let urlObj = JSON.parse(url);
if (urlObj && urlObj['url']) {
return urlObj['url'];
}
} catch (e) {}*/
if (_.isString(url) && _.trim(url) !== '') {
return url;
}
return helpers.urlFormat(`/guang/${id}.html`);
};
const getIndexSeo = (params, tabs) => {
let tdk = {
title: '逛|逛潮流,逛购物,官方授权正品潮流购物中心|YOHO!BUY有货',
keywords: '逛,逛潮流,逛购物',
description: 'YOHO!BUY有货逛频道,来YOHO!玩潮流!潮搭大解析!年轻人潮流购物中心,中国潮流购物风向标,吴亦凡重磅代言!YOHO!BUY有货100%正品保证,支持货到付款。'
};
params = params || {};
if (params.hasOwnProperty('type')) {
let tab = _.find(tabs, {isActive: true});
if (tab && tab.type) {
Object.assign(tdk, {
title: `潮流${tab.type}-逛|YOHO!BUY有货`,
keywords: `潮流${tab.type}`,
description: `YOHO!BUY有货潮流${tab.type}!`
});
}
}
return tdk;
};
const getEditorSeo = (name) => {
return {
title: `潮流编辑${name}|YOHO!BUY有货`,
keywords: `潮流编辑${name}`,
description: `YOHO!BUY有货潮流编辑${name}!`
};
};
const getTagSeo = (tagName) => {
return {
title: `${tagName}|YOHO!BUY有货`,
keywords: `${tagName}`,
description: `YOHO!BUY有货潮流${tagName}!`
};
};
module.exports = {
getGenderByCookie,
getUdid,
getArticleUrl,
getIndexSeo,
getEditorSeo,
getTagSeo
};