Authored by yyq

seo url 改造

@@ -127,7 +127,42 @@ exports.new = (req, res, next) => { @@ -127,7 +127,42 @@ exports.new = (req, res, next) => {
127 127
128 res.render('list/index', resData); 128 res.render('list/index', resData);
129 }).catch(next); 129 }).catch(next);
  130 +};
  131 +
  132 +/**
  133 + * 新品到着(带频道)
  134 + * @param {[type]} req [description]
  135 + * @param {[type]} res [description]
  136 + * @return {[type]} [description]
  137 + */
  138 +exports.newWithChannel = (req, res, next) => {
  139 + let channel = req.params[0];
  140 +
  141 + req.query = req.query || {};
  142 +
  143 + // 根据 XXXX-new 中的频道处理查询参数
  144 + switch (channel) {
  145 + case 'boys':
  146 + req.yoho.channel = 'boys';
  147 + req.query = Object.assign({gender: '1,3', msort: '1,3,4,6,7,8,308,360'}, req.query);
  148 + break;
  149 + case 'girls':
  150 + req.yoho.channel = 'girls';
  151 + req.query = Object.assign({gender: '2,3', msort: '1,3,4,6,7,8,308,360'}, req.query);
  152 + break;
  153 + case 'kids':
  154 + req.yoho.channel = 'kids';
  155 + req.query = Object.assign({gender: '1,2,3', msort: '365'}, req.query);
  156 + break;
  157 + case 'lifestyle':
  158 + req.yoho.channel = 'lifestyle';
  159 + req.query = Object.assign({gender: '1,2,3', msort: '10'}, req.query);
  160 + break;
  161 + default:
  162 + break;
  163 + }
130 164
  165 + this.new(req, res, next);
131 }; 166 };
132 167
133 /** 168 /**
@@ -9,6 +9,8 @@ @@ -9,6 +9,8 @@
9 const mRoot = '../models'; 9 const mRoot = '../models';
10 const sale = require(`${mRoot}/sale`); // sale model 10 const sale = require(`${mRoot}/sale`); // sale model
11 11
  12 +const channelList = ['boys', 'girls', 'kids', 'lifestyle'];
  13 +
12 /** 14 /**
13 * sale 首页 15 * sale 首页
14 * @param {[type]} req [description] 16 * @param {[type]} req [description]
@@ -18,6 +20,11 @@ const sale = require(`${mRoot}/sale`); // sale 页 model @@ -18,6 +20,11 @@ const sale = require(`${mRoot}/sale`); // sale 页 model
18 exports.index = (req, res, next) => { 20 exports.index = (req, res, next) => {
19 let channel = req.yoho.channel; 21 let channel = req.yoho.channel;
20 22
  23 + // SEO url 改造
  24 + if (req.params && req.params[0] && channelList.indexOf(req.params[0]) > -1) {
  25 + channel = req.params[0];
  26 + }
  27 +
21 // 真实数据输出 28 // 真实数据输出
22 sale.getSaleIndexData(channel).then(result => { 29 sale.getSaleIndexData(channel).then(result => {
23 res.render('sale/index', Object.assign({ 30 res.render('sale/index', Object.assign({
@@ -24,6 +24,21 @@ const checksName = { @@ -24,6 +24,21 @@ const checksName = {
24 limited: '限量' 24 limited: '限量'
25 }; 25 };
26 26
  27 +const sortFilterParam = (param) => {
  28 + let resData = [];
  29 +
  30 + _.forEach(param, (value, key) => {
  31 + resData.push({
  32 + key: key,
  33 + value: value
  34 + });
  35 + });
  36 +
  37 + return _.sortBy(resData, [o => {
  38 + return o.key;
  39 + }]);
  40 +};
  41 +
27 /** 42 /**
28 * 处理用于筛选的 URL , 拼接 URL 参数 43 * 处理用于筛选的 URL , 拼接 URL 参数
29 * @param originParam 当前 URL 中的参数 44 * @param originParam 当前 URL 中的参数
@@ -39,10 +54,13 @@ const handleFilterUrl = (originParam, newParam, delParam) => { @@ -39,10 +54,13 @@ const handleFilterUrl = (originParam, newParam, delParam) => {
39 tempOriginParam = Object.assign(tempOriginParam, originParam, newParam); 54 tempOriginParam = Object.assign(tempOriginParam, originParam, newParam);
40 delete tempOriginParam.uid; 55 delete tempOriginParam.uid;
41 56
42 - _.forEach(tempOriginParam, function(value, key) {  
43 - if (!delParam[key] && value) { 57 + _.forEach(sortFilterParam(tempOriginParam), info => {
  58 + if (!delParam[info.key] && info.value) {
44 // NOTE: 这里会对 query 进行编码,因为 query 有可以能是中文 59 // NOTE: 这里会对 query 进行编码,因为 query 有可以能是中文
45 - dest += key === 'query' ? `${key}=${encodeURIComponent(value)}&` : `${key}=${value}&`; 60 + if (info.key === 'query') {
  61 + info.value = encodeURIComponent(info.value);
  62 + }
  63 + dest += `${info.key}=${info.value}&`;
46 } 64 }
47 }); 65 });
48 66
@@ -65,7 +83,12 @@ const handleCheckedData = (params, origin, param) => { @@ -65,7 +83,12 @@ const handleCheckedData = (params, origin, param) => {
65 let tempPatam = _.cloneDeep(params); 83 let tempPatam = _.cloneDeep(params);
66 84
67 // 删除选中 85 // 删除选中
68 - delete tempPatam[param]; 86 + if (param === 'gender') {
  87 + // 某些特殊带频道信息页面,清除性别,需将gender设为1,2,3 (2017-3 配合SEO进行URL改造)
  88 + tempPatam[param] = '1,2,3';
  89 + } else {
  90 + delete tempPatam[param];
  91 + }
69 92
70 dest.push({ 93 dest.push({
71 name: value.name, 94 name: value.name,
@@ -779,7 +802,8 @@ exports.handleFilterData = (origin, params, total) => { @@ -779,7 +802,8 @@ exports.handleFilterData = (origin, params, total) => {
779 } 802 }
780 803
781 // 清除所有选中数据 804 // 清除所有选中数据
782 - let remainParams = {}; 805 + // 某些特殊带频道信息页面,清除性别,需将gender设为1,2,3 (2017-3 配合SEO进行URL改造)
  806 + let remainParams = {gender: '1,2,3'};
783 807
784 if (params.id) { 808 if (params.id) {
785 remainParams.id = params.id; 809 remainParams.id = params.id;
@@ -46,6 +46,7 @@ const newArrive = require(`${cRoot}/newArrive`); @@ -46,6 +46,7 @@ const newArrive = require(`${cRoot}/newArrive`);
46 46
47 // 商品促销routers 47 // 商品促销routers
48 router.get('/sale', sale.index); // sale 首页 48 router.get('/sale', sale.index); // sale 首页
  49 +router.get(/\/(.*)-sale/, sale.index); // sale 首页(SEO改造)
49 router.get('/sale/discount/detail', sale.discount); // 折扣专场详情页 50 router.get('/sale/discount/detail', sale.discount); // 折扣专场详情页
50 router.get('/sale/vip', sale.vip); // VIP 活动专区 51 router.get('/sale/vip', sale.vip); // VIP 活动专区
51 router.get('/sale/breakingYards', sale.breakingYards); // 断码区 52 router.get('/sale/breakingYards', sale.breakingYards); // 断码区
@@ -93,6 +94,7 @@ router.get('/list/index', gbk2utf, list.index); @@ -93,6 +94,7 @@ router.get('/list/index', gbk2utf, list.index);
93 94
94 // 新品到着 95 // 新品到着
95 router.get('/list/new', list.new); 96 router.get('/list/new', list.new);
  97 +router.get(/\/list\/(.*)-new/, list.newWithChannel);
96 98
97 // 品牌店铺 99 // 品牌店铺
98 router.get('/index/brand', list.brand); // 品牌店铺页 100 router.get('/index/brand', list.brand); // 品牌店铺页
@@ -52,6 +52,8 @@ module.exports = () => { @@ -52,6 +52,8 @@ module.exports = () => {
52 { // eslint-disable-line 52 { // eslint-disable-line
53 if (!req.path || req.path === '/') { 53 if (!req.path || req.path === '/') {
54 req.url = '/product/list/index'; 54 req.url = '/product/list/index';
  55 + } else if (/\/(.*)-new/.exec(req.path) !== null) {
  56 + req.url = `/product/list/${RegExp.$1}-new`;
55 } else if (req.path === '/new') { 57 } else if (req.path === '/new') {
56 req.url = '/product/list/new'; 58 req.url = '/product/list/new';
57 } 59 }
@@ -73,6 +75,9 @@ module.exports = () => { @@ -73,6 +75,9 @@ module.exports = () => {
73 } else if (req.path === '/about') { 75 } else if (req.path === '/about') {
74 req.url = `/product/index/about?domain=${req.subdomains[0]}`; 76 req.url = `/product/index/about?domain=${req.subdomains[0]}`;
75 req.query.domain = req.subdomains[0]; 77 req.query.domain = req.subdomains[0];
  78 + } else if (/\/shop([\d]+)-about/.exec(req.path) !== null) {
  79 + req.query.shopId = RegExp.$1;
  80 + req.url = '/product/index/about';
76 } 81 }
77 break; 82 break;
78 } 83 }