Authored by 周少峰

Merge branch 'feature/wwwGuang' into gray

... ... @@ -55,10 +55,28 @@ const keywordsPage = () => {
});
};
// 逛详情
const getArticleUrls = () => {
let urls = [];
return Service.get('/guang/api/v2/article/getLastArticleList', {limit: 1000}, {cache: 86400}).then(res => {
_.forEach(_.get(res, 'data.artList', ''), val => {
urls.push({
url: `https:${helpers.urlFormat(`/guang/${val.articleId}.html`, null)}`,
changefreq: 'daily',
priority: 0.3
});
});
return urls;
});
};
// www 地图数据
const wwwXmlData = () => {// eslint-disable-line
return Promise.all([keywordsPage(), getStaticUrls(_.get(staticUrls, 'www'))]).then(result => {
return _.concat(result[1], result[0]);
return Promise.all([keywordsPage(), getStaticUrls(_.get(staticUrls, 'www')), getArticleUrls()]).then(result => {
return _.concat(result[1], result[0], result[2]);
});
};
... ... @@ -104,34 +122,10 @@ const itemXmlData = () => {// eslint-disable-line
});
};
const getArticleUrls = () => {
let urls = [];
return Service.get('/guang/api/v2/article/getLastArticleList', {limit: 1000}, {cache: 86400}).then(res => {
_.forEach(_.get(res, 'data.artList', ''), val => {
urls.push({
url: `https:${helpers.urlFormat(`/${val.articleId}.html`, '', 'guang')}`,
changefreq: 'daily',
priority: 0.3
});
});
return urls;
});
};
// guang 地图数据
const guangXmlData = () => {// eslint-disable-line
return Promise.all([getStaticUrls(_.get(staticUrls, 'guang')), getArticleUrls()]).then(res => {
return _.union(res[0], res[1]);
});
};
// 站点地图
const siteMap = (req, res, next) => {
let siteList = ['www', 'list', 'item', 'guang'],
let siteList = ['www', 'list', 'item'],
subdomain = req.subdomains[0] || 'www';
if (_.find(siteList, subdomain)) {
... ...
... ... @@ -39,7 +39,7 @@ exports.index = (req, res, next) => {
reqCtx.getArticleList(gender, type, uid, udid, page, '', '', pageSize, channel, true),
reqCtx.getHotTags(page, pageSize, channel, isHotDegrade),
reqCtx.getAds(channel, isAdDegrade),
reqCtx.getRecoArticles(gender, 1, 10, channel),
reqCtx.getRecoArticles(gender, 1, 10),
headerModel.requestHeaderData(channel),
reqCtx.getTopList(gender, uid, udid, page, true)
]).then(ret => {
... ... @@ -102,7 +102,7 @@ exports.tags = (req, res, next) => {
reqCtx.getArticleList(gender, 0, uid, udid, page, query, '', pageSize, channel, true),
reqCtx.getHotTags(1, 20, channel, isHotDegrade),
reqCtx.getAds(channel, isAdDegrade),
reqCtx.getRecoArticles(gender, 1, 10, channel),
reqCtx.getRecoArticles(gender, 1, 10),
headerModel.requestHeaderData(channel)
]).then(ret => {
... ... @@ -162,7 +162,7 @@ exports.editor = (req, res, next) => {
reqCtx.getArticleList(gender, null, uid, udid, page, '', authorId, pageSize, channel, true),
reqCtx.getHotTags(1, 20, channel, isHotDegrade),
reqCtx.getAds(channel, isAdDegrade),
reqCtx.getRecoArticles(gender, 1, 10, channel),
reqCtx.getRecoArticles(gender, 1, 10),
headerModel.requestHeaderData(channel)
]).then(ret => {
... ... @@ -199,7 +199,7 @@ exports.editor = (req, res, next) => {
*/
exports.detail = (req, res, next) => {
let id = req.params.id || req.query.id;
let id = req.params.id || req.query.id || req.params[0];
let page = req.query.page || 1;
let pageSize = req.query.pageSize || 10;
let col = req.query.col || 0;
... ... @@ -254,7 +254,7 @@ exports.detail = (req, res, next) => {
reqCtx.getArticleComments(udid, uid, id, page, pageSize),
reqCtx.getArticleBaseInfo(id, uid, udid),
reqCtx.getArticleRelateBrand(id),
reqCtx.getRecoArticles(gender, 1, 10, channel),
reqCtx.getRecoArticles(gender, 1, 10),
reqCtx.getAds(channel, isAdDegrade),
tdk('article', id, req)
];
... ... @@ -266,7 +266,7 @@ exports.detail = (req, res, next) => {
}
if (info.tag) {
promises.push(req.ctx(guangModel).getRelateArticleList(id, info.tag, 2, channel));
promises.push(req.ctx(guangModel).getRelateArticleList(id, info.tag, 2));
} else {
promises.push({});
}
... ...
... ... @@ -64,7 +64,7 @@ const getUdid = (req, res) => {
* @param type id 产品编号
* @return type url
*/
const getArticleUrl = (url, id, channel) => {
const getArticleUrl = (url, id) => {
/* 格式由url:{url:'aaa'} 更改为 url: 'aaa'
try {
... ... @@ -79,13 +79,7 @@ const getArticleUrl = (url, id, channel) => {
return url;
}
let param = {};
if (channel) {
param.channel = channel;
}
return helpers.urlFormat(`/${id}.html`, param, 'guang');
return helpers.urlFormat(`/guang/${id}.html`);
};
const getIndexSeo = (params, tabs) => {
... ...
... ... @@ -78,20 +78,16 @@ module.exports = class extends global.yoho.BaseModel {
return query ? _.concat(path, [{ name: query, pathTitle: query}]) : path;
}
_formatTag(tagData, channel) {
_formatTag(tagData) {
let name = tagData.name,
param = {
query: name
};
if (channel) {
param.channel = channel;
}
return {
tag: name,
name: name,
url: helpers.urlFormat('/tags/index', param, 'guang')
url: helpers.urlFormat('/guang/tags/index', param)
};
}
... ... @@ -128,7 +124,7 @@ module.exports = class extends global.yoho.BaseModel {
// isReco: articleData.is_recommended && Number(articleData.is_recommended) === 1 ? true : false,
url: +articleData.category_id === 9999 ?
helpers.urlFormat(`/${_.get(articleData, 'product_list[0].product_skn', 0)}.html`, null, 'item') :
ghelper.getArticleUrl(articleData.url, articleData.id, channel),
ghelper.getArticleUrl(articleData.url, articleData.id),
img: helpers.image(articleData.src, width, height, 1),
isSquareImg: isSquareImage,
title: articleData.title,
... ... @@ -412,13 +408,9 @@ module.exports = class extends global.yoho.BaseModel {
query: it.tag_name
};
if (channel) {
param.channel = channel;
}
return {
tagName: it.tag_name,
url: helpers.urlFormat('/tags/index', param, 'guang')
url: helpers.urlFormat('/guang/tags/index', param)
};
});
});
... ... @@ -543,7 +535,7 @@ module.exports = class extends global.yoho.BaseModel {
/**
* 推荐文章
*/
getRecoArticles(gender, page, limit, channel) {
getRecoArticles(gender, page, limit) {
let data = {
gender: gender,
... ... @@ -568,7 +560,7 @@ module.exports = class extends global.yoho.BaseModel {
let it = res.data[i];
let reco = {
url: ghelper.getArticleUrl(it.url, it.id, channel),
url: ghelper.getArticleUrl(it.url, it.id),
title: it.title
};
... ... @@ -962,7 +954,7 @@ module.exports = class extends global.yoho.BaseModel {
* @param bool $onlyUrl
* @return mixed
*/
getRelateArticleList(aid, tag, size, channel) {
getRelateArticleList(aid, tag, size) {
size = size || 3;
let data = {
... ... @@ -983,7 +975,7 @@ module.exports = class extends global.yoho.BaseModel {
if (res && res.code === 200 && res.data) {
return _.map(res.data, it => {
it.thumb = helpers.image(it.thumb, 264, 173, 1);
it.url = ghelper.getArticleUrl(it.url, it.id, channel);
it.url = ghelper.getArticleUrl(it.url, it.id);
return it;
});
}
... ...
... ... @@ -7,9 +7,9 @@
const helpers = global.yoho.helpers;
module.exports.editorUrl = function(channel, authorId) {
return helpers.urlFormat(`/author-${channel}-${authorId}/`, null, 'guang');
return helpers.urlFormat(`/guang/author-${channel}-${authorId}/`, null);
};
module.exports.listUrl = function(channel, type) {
return helpers.urlFormat(`/${channel}-t${type}/`, null, 'guang');
return helpers.urlFormat(`/guang/${channel}-t${type}/`, null);
};
... ...
... ... @@ -14,6 +14,7 @@ const sitemap = require('../3party/controllers/sitemap');
router.get(['/', '/index/index'], guangController.index);
router.get(['/detail/:id', '/info/index'], guangController.detail); // guang/info/index
router.get(/^\/([\d]+)(.*)/, guangController.detail);
router.get('/tags/index', guangController.tags);
router.get('/Index/editor', guangController.editor);
... ...
... ... @@ -39,6 +39,13 @@ module.exports = {
lastmod: today,
changefreq: 'daily',
priority: 0.3
},
guang: {
loc: ['https://www.yohobuy.com/guang/'],
lastmod: today,
changefreq: 'daily',
priority: 0.3
}
},
... ... @@ -68,14 +75,6 @@ module.exports = {
priority: 0.3
},
// 逛 编辑列表/标签列表/逛详情动态添加
guang: {
loc: ['https://guang.yohobuy.com/boys/', 'https://guang.yohobuy.com/girls/', 'https://guang.yohobuy.com/kids/', 'https://guang.yohobuy.com/lifestyle/'],
lastmod: today,
changefreq: 'daily',
priority: 0.3
},
// 商品详情动态添加
item: {
loc: [],
... ...
... ... @@ -7,108 +7,12 @@
const helpers = global.yoho.helpers;
const TYPE = require('../type');
const MOBILE_DOMAIN = '//guang.m.yohobuy.com';
module.exports = [
// 老的首页
{
type: TYPE.redirect,
origin: (req) => {
return req.path === '/';
},
origin: /^\/(.*)/,
target: (req) => {
return helpers.urlFormat(`/${req.yoho.channel}/`, null, 'guang');
}
},
// 首页
{
type: TYPE.rewrite,
origin: /^\/(boys|girls|kids|lifestyle)(\/*)$/,
target: (req, match, channel) => {
req.query.channel = channel;
return `/guang/?chanel=${channel}`;
}
},
// 老的首页 + 类型 + 翻页
{
type: TYPE.redirect,
origin: req => /index\/index/i.test(req.path),
target: (req) => {
return helpers.urlFormat(
`/${req.yoho.channel}-t${req.query.type || 0}${req.query.page ? '-p' + req.query.page : ''}/`,
null,
'guang'
);
}
},
// 首页 + 类型
{
type: TYPE.rewrite,
origin: /^\/(boys|girls|kids|lifestyle)-t([\d]+)(\/*)$/,
target: (req, match, channel, type) => {
req.query.channel = channel;
req.query.type = type;
return `/guang/?chanel=${channel}&type=${type}`;
}
},
// 列表页 + 类型 + 翻页
{
type: TYPE.rewrite,
origin: /^\/(boys|girls|kids|lifestyle)-t([\d]+)-p([\d]+)(\/*)$/,
target: (req, match, channel, type, page) => {
req.query.channel = channel;
req.query.type = type;
req.query.page = page;
return `/guang/index/index/?type=${type}&channel=${page}`;
}
},
// 老的编缉首页
{
type: TYPE.redirect,
origin: (req) => {
return /index\/editor/i.test(req.path);
},
target: (req) => {
let channel = req.yoho.channel;
let authorId = req.query.author_id;
let page = req.query.page;
if (!authorId) {
return helpers.urlFormat(`/${channel}/`, null, 'guang');
}
return helpers.urlFormat(`/author-${channel}-${authorId}${page ? '-p' + page : ''}/`, null, 'guang');
}
},
// 编缉首页
{
type: TYPE.rewrite,
origin: /^\/author-(boys|girls|kids|lifestyle)-([\d]+)(\/*)$/,
target: (req, match, channel, authorId) => {
req.query.channel = channel;
req.query.author_id = authorId;
req.mobileUrl = `${MOBILE_DOMAIN}/author-${channel}-${authorId}/`;
return `/guang/index/editor?channel=${channel}&author_id=${authorId}`;
}
},
// 编缉首页 + 翻页
{
type: TYPE.rewrite,
origin: /^\/author-(boys|girls|kids|lifestyle)-([\d]+)-p([\d]+)(\/*)$/,
target: (req, match, channel, authorId, page) => {
req.query.channel = channel;
req.query.author_id = authorId;
req.query.page = page;
req.mobileUrl = `${MOBILE_DOMAIN}/author-${channel}-${authorId}-p${page}/`;
return `/guang/index/editor?channel=${channel}&author_id=${authorId}&page=${page}`;
return helpers.urlFormat(`/guang${req.url}`, null);
}
}
];
... ...
... ... @@ -8,6 +8,7 @@
const helpers = global.yoho.helpers;
const TYPE = require('../type');
const MOBILE_DOMAIN = '//guang.m.yohobuy.com';
module.exports = [
{
... ... @@ -96,6 +97,65 @@ module.exports = [
type: TYPE.redirect,
origin: '/index.html',
target: helpers.urlFormat('/')
}
},
// 逛
// 首页
{
type: TYPE.rewrite,
origin: /^\/guang\/(boys|girls|kids|lifestyle)(\/*)$/,
target: (req, match, channel) => {
req.query.channel = channel;
return `/guang/?chanel=${channel}`;
}
},
// 首页 + 类型
{
type: TYPE.rewrite,
origin: /^\/guang\/(boys|girls|kids|lifestyle)-t([\d]+)(\/*)$/,
target: (req, match, channel, type) => {
req.query.channel = channel;
req.query.type = type;
return `/guang/?chanel=${channel}&type=${type}`;
}
},
// 列表页 + 类型 + 翻页
{
type: TYPE.rewrite,
origin: /^\/guang\/(boys|girls|kids|lifestyle)-t([\d]+)-p([\d]+)(\/*)$/,
target: (req, match, channel, type, page) => {
req.query.channel = channel;
req.query.type = type;
req.query.page = page;
return `/guang/index/index/?type=${type}&channel=${page}`;
}
},
// 编缉首页
{
type: TYPE.rewrite,
origin: /^\/guang\/author-(boys|girls|kids|lifestyle)-([\d]+)(\/*)$/,
target: (req, match, channel, authorId) => {
req.query.channel = channel;
req.query.author_id = authorId;
req.mobileUrl = `${MOBILE_DOMAIN}/author-${channel}-${authorId}/`;
return `/guang/index/editor?channel=${channel}&author_id=${authorId}`;
}
},
// 编缉首页 + 翻页
{
type: TYPE.rewrite,
origin: /^\/guang\/author-(boys|girls|kids|lifestyle)-([\d]+)-p([\d]+)(\/*)$/,
target: (req, match, channel, authorId, page) => {
req.query.channel = channel;
req.query.author_id = authorId;
req.query.page = page;
req.mobileUrl = `${MOBILE_DOMAIN}/author-${channel}-${authorId}-p${page}/`;
return `/guang/index/editor?channel=${channel}&author_id=${authorId}&page=${page}`;
}
}
];
... ...