Authored by 周少峰

list urls

... ... @@ -7,6 +7,9 @@ const sm = require('sitemap');
const staticUrls = require('../../../config/staticUrls');
const api = global.yoho.API;
const Service = global.yoho.ServiceAPI;
const headerModel = require('../../../doraemon/models/header');
const getStaticUrls = (currentStatics) => {
let urls = [];
... ... @@ -39,7 +42,35 @@ const wwwXmlData = () => {// eslint-disable-line
// list 地图数据
const listXmlData = () => {// eslint-disable-line
return getStaticUrls(_.get(staticUrls, 'list'));
return Promise.all([getStaticUrls(_.get(staticUrls, 'list')), headerModel.requestHeaderData()]).then(result => {
// 获取导航中的列表链接
let listNav = [],
listPatten = /list\.yohobuy\.com/;
_.forEach(_.get(result[1], 'headerData.subNavGroup'), val => {
_.forEach(val.subNav, sub => {
if (listPatten.test(sub.link)) {
listNav.push({
url: sub.link,
changefreq: 'daily',
priority: 0.3
})
}
_.forEach(_.get(sub, 'thirdNav'), third => {
if (listPatten.test(third.link)) {
listNav.push({
url: third.link,
changefreq: 'daily',
priority: 0.3
})
}
})
})
})
return _.union(result[0], _.uniqBy(listNav, 'url'));
});
};
// item 地图数据
... ... @@ -47,16 +78,16 @@ const itemXmlData = () => {// eslint-disable-line
let urls = [];
return api.get('', {method: 'web.product.bdPromotion'}, {cache: 86400}).then(res => {
_.forEach(_.get(res,'data', ''), val => {
_.forEach(_.get(res, 'data', ''), val => {
urls.push({
url: `https:${helpers.getUrlBySkc(val.id)}`,
changefreq: 'daily',
priority: 0.3
});
})
});
return urls;
})
});
};
const getArticleUrls = () => {
... ... @@ -64,17 +95,17 @@ const getArticleUrls = () => {
return Service.get('/guang/api/v2/article/getLastArticleList', {limit: 1000}, {cache: 86400}).then(res => {
_.forEach(_.get(res,'data.artList', ''), val => {
_.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
... ... @@ -106,7 +137,7 @@ const siteMap = (req, res, next) => {
res.header('Content-Type', 'application/xml');
res.send(xml);
});
}).catch(next)
}).catch(next);
};
module.exports = {
... ...