Authored by 陈峰

guang和商品详情seo路由优化

... ... @@ -233,7 +233,7 @@ exports.index = (req, res, next) => {
value.cn_alphabet = productNameProcess(value.cn_alphabet);
}
value.url = helpers.urlFormat(`/product/pro_${value.product_id}_${value.goodsId}/${value.cn_alphabet}.html`) + `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${value.product_skn}}}`;
value.url = helpers.urlFormat(`/product/p${value.product_id}.html`) + `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${value.product_skn}}}`;
return value;
});
... ... @@ -426,7 +426,7 @@ exports.verifystudent = (req, res, next) => {
value.cn_alphabet = productNameProcess(value.cn_alphabet);
}
value.url = helpers.urlFormat(`/product/pro_${value.product_id}_${value.goodsId}/${value.cn_alphabet}.html`) + `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${value.product_skn}}}`;
value.url = helpers.urlFormat(`/product/p${value.product_id}.html`) + `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${value.product_skn}}}`;
return value;
});
return getUser(uid).then((user) => {
... ...
... ... @@ -42,7 +42,7 @@ const getProductData = (params) => {
return '';
} else {
_.forEach(result.data, (item) => {
item.url = helpers.urlFormat(`/product/pro_${item.productId}_${item.goodsId}/${item.cnAlphabet}.html`); // eslint-disable-line
item.url = helpers.urlFormat(`/product/p${item.product_id}.html`); // eslint-disable-line
item.url = helpers.appUrlFormat(item.url, 'go.productDetail', {
product_skn: item.productSkn
});
... ...
... ... @@ -83,7 +83,13 @@ const editor = (req, res, next) => {
// 301到新路由
const editorRedirect = (req, res, next) => {
if (req.query.id) {
res.redirect(`${req.query.id}`);
let redirectUrl = '/guang/author';
if (req.yoho.channel !== req.cookies._Channel) {
redirectUrl += `-${req.yoho.channel}`;
}
redirectUrl += `-${req.query.id}/`;
res.redirect(redirectUrl);
} else {
return next();
}
... ...
... ... @@ -285,7 +285,6 @@ 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.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访问的
... ... @@ -432,7 +431,13 @@ const index = (req, res, next) => {
// 301到新路由
const indexRedirect = (req, res, next) => {
if (req.query.id) {
res.redirect(`${req.query.id}`);
let redirectUrl = '/guang/info/';
if (req.yoho.channel !== req.cookies._Channel) {
redirectUrl += `${req.yoho.channel}-`;
}
redirectUrl += `${req.query.id}.html`;
res.redirect(redirectUrl);
} else {
return next();
}
... ...
... ... @@ -185,8 +185,7 @@ const getNewProduct = (brandId, gender, url, isApp) => {
list.cn_alphabet = productNameProcess(list.cn_alphabet);
}
let productUrl = '//m.yohobuy.com/product/pro_' + list.product_id + '_' +
list.goods_list[0].goods_id + '/' + list.cn_alphabet + '.html';
let productUrl = '//m.yohobuy.com/product/p' + list.product_id + '.html';
if (isApp) {
productUrl += `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${list.product_skn}"}}`;
... ...
... ... @@ -41,7 +41,7 @@ router.post('/plusstar/resources-goodsList', plusstar.resourcesGoodsList); //
router.get('/', index.index); // 逛首页
router.get('/tags/index', index.tag); // 逛标签页
router.get('/author/index', index.editor); // 编辑简介
router.get('/author/index', rewrite.channel, index.editorRedirect); // 编辑简介
router.get(/^\/author-([^\/]+)/, rewrite.resolve, index.editor); // 编辑简介 SEO优化
router.get('/index/page', index.pageData); // 逛列表页面的资讯分页
... ... @@ -50,8 +50,9 @@ router.post('/opt/praiseArticle', opt.praiseArticle); // 资讯文章点赞 (H5
router.post('/opt/collectArticle', opt.collectArticle); // 资讯文章收藏 (H5里显示收藏)
router.post('/opt/favoriteBrand', opt.favoriteBrand); // 品牌收藏
router.get('/info/index', info.index); // 逛详情页
// router.get(/^\/info\/(.*?-\d+)/, rewrite.resolve, info.index); // 逛详情页 SEO优化
router.get('/info/index', rewrite.channel, info.indexRedirect); // 逛详情页
router.get(/^\/info\/(.*?)\.html/, 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内容页
... ...
... ... @@ -53,9 +53,7 @@ const favProduct = (uid, page, limit) => {
if (val.goodsId && val.cnAlphabet) {
obj = _.assign(obj, {
link: config.siteUrl + '/product/pro_' +
val.productId + '_' + val.goodsId + '/' +
val.cnAlphabet + '.html'
link: config.siteUrl + '/product/p' + val.productId + '.html'
});
} else {
obj = _.assign(obj, {
... ... @@ -177,8 +175,7 @@ const favfavBrand = (uid, page, limit) => {
_.forEach(val.newProduct, function (data, key) {
obj.productList.push({
link: '/product/pro_' + data.productId + '_' +
data.goods[0].id + '/' + data.cnAlphabet + '.html',
link: '/product/p' + data.productId + '.html',
imgUrl: data.defaultImages,
price: '¥' + Number(data.marketPrice).toFixed(2),
discount: data.marketPrice > data.salesPrice ? '¥' + Number(data.salesPrice).toFixed(2) : false,
... ...
... ... @@ -14,7 +14,9 @@ const newDetail = {
let goodsId;
let productSkn;
if (req.params[0] && req.params[1]) {
if (req.query.id) {
id = req.query.id;
} else if (req.params[0] && req.params[1]) {
id = req.params[0];
goodsId = req.params[1];
} else if (req.params[0]) {
... ... @@ -57,6 +59,20 @@ const newDetail = {
}).catch(next);
},
// 301到新路由
indexRedirect(req, res, next) {
if (req.params[0] && req.params[1]) {
let redirectUrl = '/product/';
if (req.yoho.channel !== req.cookies._Channel) {
redirectUrl += `${req.yoho.channel}-`;
}
redirectUrl += `p${req.params[0]}.html`;
return res.redirect(redirectUrl);
}
next();
},
/*
* 商品基本信息 SKN 进入 pagecache重构
... ...
... ... @@ -104,8 +104,7 @@ const selectHotrank = (yhChannel, gender, sort, tabId, limit, page, notab) => {
}
one = _.assign(one, {
url: '/product/pro_' + data.product_id + '_' + data.goods_list[0].goods_id +
'/' + data.cn_alphabet + '.html',
url: '/product/p' + data.product_id + '.html',
thumb: data.default_images,
rank: limit * (page - 1) + index + 1,
name: data.product_name,
... ...
... ... @@ -36,7 +36,7 @@ const _formatProduct = (data) => {
let goods = {
salePrice: value.sales_price ? value.sales_price : '',
price: value.market_price ? value.market_price : '',
url: helpers.urlFormat(`/product/pro_${value.product_id}_${value.goodsId}/${value.cn_alphabet}.html`),
url: helpers.urlFormat(`/product/p${value.product_id}.html`),
thumb: value.default_images,
name: value.product_name
... ...
... ... @@ -34,7 +34,7 @@ const getPreferenceData = (data) => {
product_name: value.product_name,
default_images: value.default_images,
is_soon_sold_out: value.is_soon_sold_out === 'Y',
url: helpers.urlFormat(`/product/pro_${value.product_id}_${value.goodsId}/${value.cn_alphabet}.html`),
url: helpers.urlFormat(`/product/p${value.product_id}.html`),
market_price: value.market_price,
sales_price: value.sales_price
};
... ...
... ... @@ -60,10 +60,10 @@ const bundle = require(`${cRoot}/bundle`);
// 因为正则匹配原因,秒杀详情页路由要放在普通详情页前面,待解决
router.get(/^\/seckill\/show_([\d]+)/, seckillDetail.indexSkn); // 秒杀商品详情页 SKN 进入
router.get(/^\/seckill\/pro_([\d]+)_([\d]+)/, seckillDetail.index); // 秒杀商品详情页进入
router.get(/^\/pro_([\d]+)_([\d]+)/, newDetail.index); // 商品详情页
router.get(/^\/pro_([\d]+)_([\d]+)/, rewrite.channel, newDetail.indexRedirect); // 商品详情页
// /show_51047967.html
router.get(/^\/show_([\d]+)/, newDetail.index); // 商品详情页 SKN 进入
// router.get(/^\/p([\d]+)\.html/, newDetail.index); // 商品详情页 SKN 进入 SEO优化
router.get(/^\/(.*?-)?p([\d]+)\.html/, rewrite.resolve, newDetail.index); // 商品详情页 进入 SEO优化
router.get('/detail/sknData.json', newDetail.sknData); // 商品咨询,评价,店铺
router.get('/detail/intro/:productskn', detail.intro); // 商品内嵌页
... ...
... ... @@ -9,15 +9,19 @@ const typeLib = require('../../config/type-lib');
const _ = require('lodash');
const resolve = (req, res, next) => {
let path = req.params[0],
let path,
params = {
channel: req.yoho.channel
};
path = _.join(_.map(req.params, v => {
return v;
}), '-');
if (!path) {
return next();
}
let conditions = path.replace('.html', '').split('-');
let conditions = path.split('-').filter(cond => cond);
_.each(conditions, condition => {
if (typeLib.channels[condition]) {
... ... @@ -28,7 +32,7 @@ const resolve = (req, res, next) => {
if (item.length === 2) {
params[item[0]] = item[1];
}
} else if (condition >= 0) {
} else if (condition >= 0 && !params.id) {
params.id = _.parseInt(condition);
}
});
... ...
... ... @@ -281,7 +281,7 @@ const formatProduct = (productData, showTags, showNew, showSale, width, height,
productData.cn_alphabet = productNameProcess(productData.cn_alphabet);
}
let url = encodeURI(helpers.urlFormat(`/product/pro_${productData.product_id}_${productData.goods_list[0].goods_id}/${productData.cn_alphabet}.html`));
let url = encodeURI(helpers.urlFormat(`/product/p${productData.product_id}.html`));
result.url = url.replace('http://', '//');
... ...
... ... @@ -164,7 +164,7 @@ exports.processProductList = (list, options) => {
product.cn_alphabet = productNameProcess(product.cn_alphabet);
}
product.url = helpers.urlFormat(`/product/pro_${product.product_id}_${product.goods_list[0].goods_id}/${product.cn_alphabet}.html`); // eslint-disable-line
product.url = helpers.urlFormat(`/product/p${product.product_id}.html`); // eslint-disable-line
// APP访问需要加附加的参数
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
... ...