Authored by htoooth

fix

@@ -11,6 +11,7 @@ const _ = require('lodash'); @@ -11,6 +11,7 @@ const _ = require('lodash');
11 const guangModel = require('../models/index'); 11 const guangModel = require('../models/index');
12 const headerModel = require('../../../doraemon/models/header'); 12 const headerModel = require('../../../doraemon/models/header');
13 const ghelper = require('../models/guang-helper'); 13 const ghelper = require('../models/guang-helper');
  14 +const urlHelper = require('../models/url-helper');
14 const querystring = require('querystring'); 15 const querystring = require('querystring');
15 const helpers = global.yoho.helpers; 16 const helpers = global.yoho.helpers;
16 17
@@ -58,7 +59,7 @@ exports.index = (req, res, next) => { @@ -58,7 +59,7 @@ exports.index = (req, res, next) => {
58 pageSize: pageSize, 59 pageSize: pageSize,
59 type: type, 60 type: type,
60 pathNav: pathNav, 61 pathNav: pathNav,
61 - baseUrl: helpers.urlFormat('/' + channel + `-t${type}`, null, 'guang'), 62 + baseUrl: urlHelper.listUrl(channel, type),
62 page: page, 63 page: page,
63 total: (ret[2] && ret[2].total) || 0 64 total: (ret[2] && ret[2].total) || 0
64 }, 65 },
@@ -169,7 +170,7 @@ exports.editor = (req, res, next) => { @@ -169,7 +170,7 @@ exports.editor = (req, res, next) => {
169 exRecos: ret[4], 170 exRecos: ret[4],
170 171
171 gender: gender, 172 gender: gender,
172 - baseUrl: helpers.urlFormat('/' + channel + `-author-i${authorId}`, null, 'guang'), 173 + baseUrl: urlHelper.editorUrl(channel, authorId),
173 pageSize: pageSize, 174 pageSize: pageSize,
174 pathNav: pathNav, 175 pathNav: pathNav,
175 page: page, 176 page: page,
@@ -38,7 +38,7 @@ exports.spager = function() { @@ -38,7 +38,7 @@ exports.spager = function() {
38 pageSizeVar = options.hash.pageSizeVar || 'pageSize'; 38 pageSizeVar = options.hash.pageSizeVar || 'pageSize';
39 39
40 // 清除原来page(page=1&) 重新定义page 40 // 清除原来page(page=1&) 重新定义page
41 - let clearPageReg = new RegExp(pageVar + '=[^&]*(&|$)'), 41 + let clearPageReg = /\/$/,
42 clearSizeReg = new RegExp(pageSizeVar + '=[^&]*(&|$)'), 42 clearSizeReg = new RegExp(pageSizeVar + '=[^&]*(&|$)'),
43 base = baseUrl.replace(clearPageReg, ''); 43 base = baseUrl.replace(clearPageReg, '');
44 44
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 const _ = require('lodash'); 8 const _ = require('lodash');
9 const moment = require('moment'); 9 const moment = require('moment');
10 const ghelper = require('./guang-helper'); 10 const ghelper = require('./guang-helper');
11 -const urlHelper = require('./urlHelper'); 11 +const urlHelper = require('./url-helper');
12 12
13 const helpers = global.yoho.helpers; 13 const helpers = global.yoho.helpers;
14 const serviceApi = global.yoho.ServiceAPI; 14 const serviceApi = global.yoho.ServiceAPI;
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 const helpers = global.yoho.helpers; 7 const helpers = global.yoho.helpers;
8 8
9 module.exports.editorUrl = function(channel, authorId) { 9 module.exports.editorUrl = function(channel, authorId) {
10 - return helpers.urlFormat(`/${channel}-author-i${authorId}/`, null, 'guang'); 10 + return helpers.urlFormat(`/author-${channel}-${authorId}/`, null, 'guang');
11 }; 11 };
12 12
13 module.exports.listUrl = function(channel, type) { 13 module.exports.listUrl = function(channel, type) {
@@ -31,6 +31,19 @@ module.exports = [ @@ -31,6 +31,19 @@ module.exports = [
31 } 31 }
32 }, 32 },
33 33
  34 + // 老的首页 + 类型 + 翻页
  35 + {
  36 + type: TYPE.redirect,
  37 + origin: req => /index\/index/i.test(req.path),
  38 + target: (req) => {
  39 + return helpers.urlFormat(
  40 + `/${req.yoho.channel}-t${req.query.type || 0}${req.query.page ? '-p' + req.query.page : ''}/`,
  41 + null,
  42 + 'guang'
  43 + );
  44 + }
  45 + },
  46 +
34 // 首页 + 类型 47 // 首页 + 类型
35 { 48 {
36 type: TYPE.rewrite, 49 type: TYPE.rewrite,
@@ -62,39 +75,39 @@ module.exports = [ @@ -62,39 +75,39 @@ module.exports = [
62 }, 75 },
63 target: (req) => { 76 target: (req) => {
64 let channel = req.yoho.channel; 77 let channel = req.yoho.channel;
65 - let aid = req.query.author_id; 78 + let authorId = req.query.author_id;
  79 + let page = req.query.page;
66 80
67 - if (!aid) { 81 + if (!authorId) {
68 return helpers.urlFormat(`/${channel}/`, null, 'guang'); 82 return helpers.urlFormat(`/${channel}/`, null, 'guang');
69 } 83 }
70 84
71 - req.mobileUrl = `${MOBILE_DOMAIN}/author/${aid}/`;  
72 - return helpers.urlFormat(`/${channel}-author-i${aid}/`, null, 'guang'); 85 + return helpers.urlFormat(`/author-${channel}-${authorId}${page ? '-p' + page : ''}/`, null, 'guang');
73 } 86 }
74 }, 87 },
75 88
76 // 编缉首页 89 // 编缉首页
77 { 90 {
78 type: TYPE.rewrite, 91 type: TYPE.rewrite,
79 - origin: /^\/(boys|girls|kids|lifestyle)-author-i([\d]+)(\/*)$/,  
80 - target: (req, match, p1, p2) => {  
81 - req.query.channel = p1;  
82 - req.query.author_id = p2;  
83 - req.mobileUrl = `${MOBILE_DOMAIN}/author/${p2}/`;  
84 - return `/guang/index/editor?channel=${p1}&author_id=${p2}`; 92 + origin: /^\/author-(boys|girls|kids|lifestyle)-([\d]+)(\/*)$/,
  93 + target: (req, match, channel, authorId) => {
  94 + req.query.channel = channel;
  95 + req.query.author_id = authorId;
  96 + req.mobileUrl = `${MOBILE_DOMAIN}/author-${channel}-${authorId}/`;
  97 + return `/guang/index/editor?channel=${channel}&author_id=${authorId}`;
85 } 98 }
86 }, 99 },
87 100
88 // 编缉首页 + 翻页 101 // 编缉首页 + 翻页
89 { 102 {
90 type: TYPE.rewrite, 103 type: TYPE.rewrite,
91 - origin: /^\/(boys|girls|kids|lifestyle)-author-i([\d]+)-p([\d]+)(\/*)$/,  
92 - target: (req, match, p1, p2, p3) => {  
93 - req.query.channel = p1;  
94 - req.query.author_id = p2;  
95 - req.query.page = p3;  
96 - req.mobileUrl = `${MOBILE_DOMAIN}/author/${p2}`;  
97 - return `/guang/index/editor?channel=${p1}&author_id=${p2}&page=${p3}`; 104 + origin: /^\/author-(boys|girls|kids|lifestyle)-([\d]+)-p([\d]+)(\/*)$/,
  105 + target: (req, match, channel, authorId, page) => {
  106 + req.query.channel = channel;
  107 + req.query.author_id = authorId;
  108 + req.query.page = page;
  109 + req.mobileUrl = `${MOBILE_DOMAIN}/author-${channel}-${authorId}-p${page}/`;
  110 + return `/guang/index/editor?channel=${channel}&author_id=${authorId}&page=${page}`;
98 } 111 }
99 } 112 }
100 113