Authored by 陈峰

优化rewrite

... ... @@ -26,8 +26,7 @@ let index = (req, res, next) => {
// title: '品牌一览 | Yoho!Buy有货 | 潮流购物逛不停',
showFooterTab: footerModel.getUrlData('category')
};
let channel,
gender;
let channel;
if (!req.query.channel) {
channel = '1';
... ... @@ -36,17 +35,9 @@ let index = (req, res, next) => {
} else {
channel = typeLib.channels[req.query.channel] + '';
}
if (!req.query.gender) {
gender = '1,3';
} else if (!typeLib.gender[gender]) {
gender = req.query.gender;
} else {
gender = typeLib.gender[gender];
}
let param = {
channel,
gender
channel
};
indexModel.getBrandByChannel(param.channel).then(result => {
... ... @@ -59,10 +50,16 @@ let index = (req, res, next) => {
};
// 301到新路由
let indexRedirect = (req, res, next) => {
let channel = typeLib.channelNames[req.query.channel || 1];
res.redirect(`/${channel || 'boys'}-brands`);
}
let indexRedirect = (req, res) => {
let channel;
if (req.query.channel >= 0) {
channel = typeLib.channelNames[req.query.channel];
} else {
channel = req.query.channel || req.yoho.channel;
}
res.redirect(`${channel}-brands`);
};
let brandList = (req, res, next) => {
var channel = req.query.channel || '1';
... ...
... ... @@ -27,7 +27,7 @@ router.get('/(:channel)/bottomBanner', channel.bottomBanner);
router.get('/cate', cate.index);
router.get('/brands', brandController.indexRedirect); // 品牌首页
router.get(/^\/([a-zA-Z]+)-brands/, rewrite.channel, brandController.index); // 品牌首页 SEO优化
router.get(/^\/(.*?)-brands/, rewrite.resolve, brandController.index); // 品牌首页 SEO优化
router.get('/brands/search', brandController.search); // 品牌搜索页
router.get('/brands/getBrandList', brandController.brandList); // 获取品牌列表
router.post('/brands/searchAsync', brandController.searchAsync); // 品牌搜索异步数据
... ...
... ... @@ -6,6 +6,7 @@
'use strict';
const mRoot = '../models';
const typeLib = require('../../../config/type-lib');
const indexModel = require(`${mRoot}/index`);
const headerModel = require('../../../doraemon/models/header'); // 头部model
const footerModel = require('../../../doraemon/models/footer_tab'); // 底部tab
... ... @@ -29,7 +30,7 @@ const editor = (req, res, next) => {
title = '编辑简介',
parameter = {},
isApp = req.yoho.isApp,
gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1;
gender = req.query.gender || req.query.channel && typeLib.channels[req.query.channel] || req.cookies._Channel && channels[req.cookies._Channel] || 1;
if (isApp) {
uid = req.query.uid;
... ... @@ -40,7 +41,6 @@ const editor = (req, res, next) => {
})
};
}
return Promise.all([indexModel.getAuthor(id), indexModel.getArticleList(gender, 0, uid, udid, 1, null, id)]).then(datas => {
let authorData = datas[0],
articleListData = datas[1];
... ... @@ -80,6 +80,15 @@ const editor = (req, res, next) => {
};
// 301到新路由
const editorRedirect = (req, res, next) => {
if (req.query.id) {
res.redirect(`${req.query.id}`);
} else {
return next();
}
};
/**
* [逛列表页面的资讯分页]
* @param {[type]} req [description]
... ... @@ -275,5 +284,6 @@ module.exports = {
index,
tag,
listDynamicData,
detailDynamicData
detailDynamicData,
editorRedirect
};
... ...
... ... @@ -6,6 +6,7 @@
'use strict';
const helpers = global.yoho.helpers;
const mRoot = '../models';
const typeLib = require('../../../config/type-lib');
const _ = require('lodash');
const infoModel = require(`${mRoot}/info`);
const stringProcess = require(`${global.utils}/string-process`);
... ... @@ -284,13 +285,14 @@ const _shareInfo = (id, getArticle) => {
* [逛资讯详情页]
*/
const index = (req, res, next) => {
console.log(req.query)
let id = req.query.id || req.params[0] || req.params.id,
gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1,
gender = req.query.gender || req.query.channel && typeLib.channels[req.query.channel] || req.cookies._Channel && channels[req.cookies._Channel] || 1,
isApp = req.query.app_version || req.query.appVersion || false, // 标识是不是APP访问的
parameter = {},
title = '逛',
isWeixin = req.yoho.isWechat,
channel = req.cookies._Channel,
channel = req.query.channel || req.cookies._Channel,
isqq = req.yoho.isqq,
isWeibo = req.yoho.isWeibo,
isShare;
... ... @@ -427,6 +429,15 @@ const index = (req, res, next) => {
}).catch(next);
};
// 301到新路由
const indexRedirect = (req, res, next) => {
if (req.query.id) {
res.redirect(`${req.query.id}`);
} else {
return next();
}
};
/**
* [逛mini内容页]
*/
... ... @@ -567,5 +578,6 @@ const foryoho = (req, res, next) => {
module.exports = {
index,
mini,
foryoho
foryoho,
indexRedirect
};
... ...
... ... @@ -24,7 +24,7 @@ exports.index = (req, res, next) => {
let isApp = req.query.app_version || req.query.appVersion || false;
let parameter = {};
let title = '潮流优选';
let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1;
let gender = req.query.gender || req.query.channel && typeLib.channels[req.query.channel] || req.cookies._Channel && channels[req.cookies._Channel] || 1;
if (isApp === false) {
parameter = {
... ... @@ -79,12 +79,16 @@ exports.index = (req, res, next) => {
};
// 301 到新路由
exports.indexRedirect = (req, res, next) => {
exports.indexRedirect = (req, res) => {
let channel;
if (req.query.channel) {
channel = req.query.channel;
if (req.query.channel >= 0) {
channel = typeLib.channelNames[req.query.channel];
} else if (req.query.channel) {
channel = req.query.channel;
} else if (req.query.gender) {
let gender = req.query.gender;
switch (gender) {
case typeLib.gender.boys:
gender = 1;
... ... @@ -101,8 +105,9 @@ exports.indexRedirect = (req, res, next) => {
}
channel = typeLib.channelNames[gender];
}
res.redirect(`/guang/${channel || 'boys'}-plusstar`);
}
channel = channel || req.yoho.channel;
res.redirect(`${channel}-plusstar`);
};
exports.userSkn = (req, res, next) => {
let isApp = req.body.app_version || req.body.appVersion || false;
... ...
... ... @@ -33,7 +33,7 @@ router.post('/star/setFavorite', star.setFavorite); // 收藏文章
router.get('/', homeController.index); // 逛首页
router.get('/plusstar', plusstar.indexRedirect); // 潮流优选
router.get(/^\/([a-zA-Z]+)-plusstar/, rewrite.channel, plusstar.index); // 潮流优选 SEO优化
router.get(/^\/(.*?)-plusstar/, rewrite.resolve, plusstar.index); // 潮流优选 SEO优化
router.post('/plusstar/userSkn', plusstar.userSkn); // 用户推荐skn
router.get('/plusstar/resources-template', plusstar.resourcesTemplate); // 潮流优选首页-资源位
router.post('/plusstar/resources-goodsList', plusstar.resourcesGoodsList); // 潮流优选首页-资源位-商品列表
... ... @@ -41,7 +41,7 @@ router.get('/', index.index); // 逛首页
router.get('/tags/index', index.tag); // 逛标签页
router.get('/author/index', index.editor); // 编辑简介
router.get(/^\/author\/(\d+)/, index.editor); // 编辑简介 SEO优化
router.get(/^\/author\/([a-zA-Z]+-\d+)/, rewrite.resolve, index.editor); // 编辑简介 SEO优化
router.get('/index/page', index.pageData); // 逛列表页面的资讯分页
... ... @@ -50,7 +50,7 @@ router.post('/opt/collectArticle', opt.collectArticle); // 资讯文章收藏 (H
router.post('/opt/favoriteBrand', opt.favoriteBrand); // 品牌收藏
router.get('/info/index', info.index); // 逛详情页
router.get(/^\/info\/(\d+)/, info.index); // 逛详情页 SEO优化
router.get(/^\/info\/([a-zA-Z]+-\d+)/, rewrite.resolve, info.index); // 逛详情页 SEO优化
router.get('/:id.html', info.index); // 逛详情页(兼容 PC 跳转过来的链接)
router.get('/info/mini', info.mini); // 逛mini内容页
router.get('/info/foryoho', info.foryoho); // 逛foryoho内容页
... ...
... ... @@ -13,6 +13,7 @@ const newModel = require(`${mRoot}/new`);
const searchModel = require(`${mRoot}/search`);
const _ = require('lodash');
const helpers = global.yoho.helpers;
const typeLib = require('../../../config/type-lib');
// 新品到着(blk)
const blkNewGoods = (req, res, next) => {
... ... @@ -79,10 +80,16 @@ const newGoods = (req, res, next) => {
};
// 301到新路由
const newGoodsRedirect = (req, res, next) => {
let channel = req.query.channel || 'boys';
res.redirect(`/product/${channel}-new`);
}
const newGoodsRedirect = (req, res) => {
let channel;
if (req.query.channel >= 0) {
channel = typeLib.channelNames[req.query.channel];
} else {
channel = req.query.channel || req.yoho.channel;
}
res.redirect(`${channel}-new`);
};
/**
* 重构的新品到着页面
... ...
... ... @@ -10,6 +10,7 @@ const mRoot = '../models';
// const cookie = require(`${library}/cookie`);
const headerModel = require('../../../doraemon/models/header');
const saleModel = require(`${mRoot}/sale`);
const typeLib = require('../../../config/type-lib');
// const queryParam = {
// brand: '0',
... ... @@ -68,11 +69,13 @@ let index = (req, res, next) => {
let params = _processPublicData(req, 'SALE', 'sale', backUrl);
params.channel = req.query.channel || params.channel;
saleModel.getSaleData(params.channel).then((result) => {
// 扩展头部频道选择数据
Object.assign(params.renderData.pageHeader, {
saleNav: saleModel.saleNav(req.yoho.channel, req.params[0] || !req.query.channel)
saleNav: saleModel.saleNav(params.channel, req.params[0] || !req.query.channel)
});
// 此处 channel 需要读取 cookies 的 channel
... ... @@ -97,10 +100,18 @@ let index = (req, res, next) => {
};
// 301到新路由
let indexRedirect = (req, res, next) => {
let channel = req.query.channel || 'boys';
res.redirect(`/product/${channel}-sale`);
}
let indexRedirect = (req, res) => {
let channel;
if (req.query.channel >= 0) {
channel = typeLib.channelNames[req.query.channel];
} else {
channel = req.query.channel || req.yoho.channel;
}
res.redirect(`${channel}-sale`);
};
/**
* 断码区
* @param {[object]} req
... ...
... ... @@ -63,7 +63,7 @@ router.get(/^\/seckill\/pro_([\d]+)_([\d]+)/, seckillDetail.index); // 秒杀商
router.get(/^\/pro_([\d]+)_([\d]+)/, newDetail.index); // 商品详情页
// /show_51047967.html
router.get(/^\/show_([\d]+)/, newDetail.index); // 商品详情页 SKN 进入
router.get(/^\/p([\d]+)\.html/, newDetail.index); // 商品详情页 SKN 进入 SEO优化
// router.get(/^\/p([\d]+)\.html/, newDetail.index); // 商品详情页 SKN 进入 SEO优化
router.get('/detail/sknData.json', newDetail.sknData); // 商品咨询,评价,店铺
router.get('/detail/intro/:productskn', detail.intro); // 商品内嵌页
... ... @@ -89,11 +89,13 @@ router.post('/detail/consultupvote', detail.consultUpvoteOrUseful); // 商品咨
router.post('/detail/consultuseful', detail.consultUpvoteOrUseful); // 商品咨询提交接口
router.get('/sale', sale.indexRedirect);
router.get(/^\/([a-zA-Z]+)-sale/, rewrite.channel, sale.index); // 折扣专区 SEO优化
router.get(/^\/(.*?)-sale\/?$/, rewrite.resolve, sale.index); // 折扣专区 SEO优化
router.get('/sale/discount', sale.discount);
// router.get(/^\/(.*?)-sale\/discount/, rewrite.resolve, sale.discount);
router.get('/sale/discount/detail', sale.discountDetail);
router.get('/sale/breakingYards', sale.breakingYards);
// router.get(/^\/(.*?)-sale\/breakingYards/, rewrite.resolve, sale.breakingYards); // SEO优化
router.get('/sale/vip', sale.vip);
router.get('/sale/discount/getTime', sale.getTime);
... ... @@ -164,7 +166,7 @@ router.get('/opt/favoriteBrand', list.favoriteBrand);
router.get('/new', news.newGoodsRedirect);
// 新品到着 SEO优化
router.get(/^\/([a-zA-Z]+)-new/, rewrite.channel, news.newGoods);
router.get(/^\/(.*?)-new/, rewrite.resolve, news.newGoods);
router.get('/list/new', news.newGoods); // 兼容 PC 的链接
router.get('/new/selectNewSale', news.selectNewSale);
... ...
... ... @@ -15,10 +15,10 @@ const channels = {
};
const channelNames = {
'1': 'boys',
'2': 'girls',
'3': 'kids',
'4': 'lifestyle'
[1]: 'boys',
[2]: 'girls',
[3]: 'kids',
[4]: 'lifestyle'
};
const gender = {
... ...
... ... @@ -6,34 +6,40 @@
'use strict';
const typeLib = require('../../config/type-lib');
const _ = require('lodash');
const gender = (req, res, next) => {
let genderName = req.params[0];
const resolve = (req, res, next) => {
let path = req.params[0],
params = {
channel: req.yoho.channel
};
if (!genderName || !typeLib.gender[genderName]) {
if (!path) {
return next();
}
req.query.gender = typeLib.gender[genderName];
return next();
};
let conditions = path.replace('.html', '').split('-');
const channel = (req, res, next) => {
let channelName = req.params[0];
_.each(conditions, condition => {
if (typeLib.channels[condition]) {
params.channel = condition;
} else if (condition.indexOf('_') >= 0) {
let item = condition.split('_');
if (!channelName) {
return next();
}
req.query.channel = channelName;
req.yoho.channel = channelName;
res.locals.channel = channelName;
res.locals.pageChannel = {[channelName]: true};
if (typeLib.channels[channelName] <= 2) {
req.query.gender = typeLib.gender[channelName];
}
return next();
if (item.length === 2) {
params[item[0]] = item[1];
}
} else if (/\d+/.test(condition)) {
params.id = _.parseInt(condition);
}
});
req.yoho.channel = params.channel;
res.locals.channel = params.channel;
res.locals.pageChannel = { [params.channel]: true };
res.locals.setChannel = true;
Object.assign(req.query, params);
next();
};
module.exports = {
gender,
channel
resolve
};
... ...
{{#pageHeader}}
{{# @root.pageChannel}}
<header id="yoho-header" class="yoho-header{{#if boys}} boys{{/if}}{{#if girls}} girls{{/if}}{{#if kids}} kids{{/if}}{{#if lifeStyle}} life-style{{/if}}{{#if lifestyle}} life-style{{/if}}">
<header id="yoho-header" class="yoho-header{{#if @root.setChannel}} set-channel{{/if}}{{#if boys}} boys{{/if}}{{#if girls}} girls{{/if}}{{#if kids}} kids{{/if}}{{#if lifeStyle}} life-style{{/if}}{{#if lifestyle}} life-style{{/if}}">
{{^}}
<header id="yoho-header" class="yoho-header">
{{/ @root.pageChannel}}
... ... @@ -47,7 +47,7 @@
{{/if}}
{{#navBtn}}
{{# @root.pageChannel}}
<div class="homebuttom hide {{#if boys}} boys{{/if}}{{#if girls}} girls{{/if}}{{#if kids}} kids{{/if}}{{#if lifeStyle}} life-style{{/if}}{{#if lifestyle}} life-style{{/if}}">
<div class="homebuttom hide{{#if @root.setChannel}} set-channel{{/if}} {{#if boys}} boys{{/if}}{{#if girls}} girls{{/if}}{{#if kids}} kids{{/if}}{{#if lifeStyle}} life-style{{/if}}{{#if lifestyle}} life-style{{/if}}">
{{^}}
<div class="homebuttom hide">
{{/ @root.pageChannel}}
... ...
... ... @@ -370,36 +370,38 @@ function givePoint(parameter) {
var header = $('#yoho-header, .homebuttom');
var footer = $('.footer-tab .tab-item.current');
if (!/^\/home/.test(location.pathname)) {
switch (channel) {
case 'boys':
if (!header.hasClass('boys')) {
header.addClass('boys');
}
break;
case 'girls':
if (!header.hasClass('girls')) {
header.addClass('girls');
}
break;
case 'lifestyle':
if (!header.hasClass('life-style')) {
header.addClass('life-style');
}
break;
case 'kids':
if (!header.hasClass('kids')) {
header.addClass('kids');
}
break;
default:
if (!header.hasClass('boys')) {
header.addClass('boys');
}
break;
if (!header.hasClass('set-channel')) {
if (!/^\/home/.test(location.pathname)) {
switch (channel) {
case 'boys':
if (!header.hasClass('boys')) {
header.addClass('boys');
}
break;
case 'girls':
if (!header.hasClass('girls')) {
header.addClass('girls');
}
break;
case 'lifestyle':
if (!header.hasClass('life-style')) {
header.addClass('life-style');
}
break;
case 'kids':
if (!header.hasClass('kids')) {
header.addClass('kids');
}
break;
default:
if (!header.hasClass('boys')) {
header.addClass('boys');
}
break;
}
} else {
header.removeClass('girls', 'life-style', 'kids').addClass('boys');
}
} else {
header.removeClass('girls', 'life-style', 'kids').addClass('boys');
}
switch (channel) {
... ...
... ... @@ -83,7 +83,7 @@ function getUrlParam(name) {
}
defaultOpt = $.extend({
yh_channel: getUrlParam('channel') || 'boys',
yh_channel: getUrlParam('channel') || defaultOpt.channel || 'boys', //TODO GO ON!
saleType: 1
}, defaultOpt);
... ...
... ... @@ -114,7 +114,6 @@ const formatArticle = (articleData, showTag, isApp, showAuthor, uid, reqQueryStr
} else {
// 编辑人员 app跳转url处理 20160601
let isLogin = uid ? true : false;
articleData.author.url = `${helpers.https(articleData.author.url)}&openby:yohobuy={"action":"go.h5","params":{"param":{},"share":"","id":${articleData.author.author_id},"type":0,"islogin":"${isLogin}","url":"${articleData.author.url}"}}`;
}
... ...