...
|
...
|
@@ -7,7 +7,6 @@ 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 = [];
|
...
|
...
|
@@ -34,36 +33,6 @@ const getStaticUrls = (currentStatics) => { |
|
|
return Promise.resolve(urls);
|
|
|
};
|
|
|
|
|
|
// m 地图数据
|
|
|
const mXmlData = () => {// eslint-disable-line
|
|
|
return getStaticUrls(_.get(staticUrls, 'm'));
|
|
|
};
|
|
|
|
|
|
// list 地图数据
|
|
|
const listXmlData = () => {// eslint-disable-line
|
|
|
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: `https:${sub.link}`, changefreq: 'daily', priority: 0.3});
|
|
|
}
|
|
|
_.forEach(_.get(sub, 'thirdNav'), third => {
|
|
|
if (listPatten.test(third.link)) {
|
|
|
listNav.push({url: `https:${third.link}`, changefreq: 'daily', priority: 0.3});
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
return _.union(result[0], _.uniqBy(listNav, 'url'));
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// item 地图数据
|
|
|
const itemXmlData = () => {// eslint-disable-line
|
|
|
let urls = [];
|
...
|
...
|
@@ -71,7 +40,7 @@ const itemXmlData = () => {// eslint-disable-line |
|
|
return api.get('', {method: 'web.product.bdPromotion'}, {cache: 86400}).then(res => {
|
|
|
_.forEach(_.get(res, 'data', ''), val => {
|
|
|
urls.push({
|
|
|
url: `https:${helpers.getUrlBySkc(val.id)}`,
|
|
|
url: 'https:' + helpers.urlFormat(`/product/${val.id}.html`, '', null),
|
|
|
changefreq: 'daily',
|
|
|
priority: 0.3
|
|
|
});
|
...
|
...
|
@@ -81,6 +50,18 @@ const itemXmlData = () => {// eslint-disable-line |
|
|
});
|
|
|
};
|
|
|
|
|
|
// m 地图数据
|
|
|
const mXmlData = () => {// eslint-disable-line
|
|
|
return Promise.all([getStaticUrls(_.get(staticUrls, 'm')), itemXmlData()]).then(result => {
|
|
|
return _.union(result[0], result[1]);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// list 地图数据
|
|
|
const listXmlData = () => {// eslint-disable-line
|
|
|
return getStaticUrls(_.get(staticUrls, 'list'));
|
|
|
};
|
|
|
|
|
|
const getArticleUrls = () => {
|
|
|
let urls = [];
|
|
|
|
...
|
...
|
@@ -107,15 +88,13 @@ const guangXmlData = () => {// eslint-disable-line |
|
|
|
|
|
// 站点地图
|
|
|
const siteMap = (req, res, next) => {
|
|
|
|
|
|
let siteList = ['m', 'list', 'item', 'guang'],
|
|
|
subdomain = req.subdomains[0] || 'm';
|
|
|
subdomain = req.subdomains[1] || 'm';
|
|
|
|
|
|
if (_.find(siteList, subdomain)) {
|
|
|
res.end('end');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
eval(subdomain + 'XmlData')().then(urls => {// eslint-disable-line
|
|
|
sm.createSitemap({
|
|
|
hostname: `https://${subdomain}.yohobuy.com`,
|
...
|
...
|
|