...
|
...
|
@@ -7,6 +7,7 @@ const sm = require('sitemap'); |
|
|
const staticUrls = require('../../../config/staticUrls');
|
|
|
const api = global.yoho.API;
|
|
|
const Service = global.yoho.ServiceAPI;
|
|
|
const redis = global.yoho.redis;
|
|
|
|
|
|
const getStaticUrls = (currentStatics) => {
|
|
|
let urls = [];
|
...
|
...
|
@@ -50,13 +51,37 @@ 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]);
|
|
|
// 关键词页面
|
|
|
const keywordsPage = (page) => {
|
|
|
return redis.getAsync(`global:yoho:seo:keywords:allIds:page:${page}`).then(function(res) {
|
|
|
let pages = [];
|
|
|
|
|
|
_.forEach(JSON.parse(res), val => {
|
|
|
pages.push({
|
|
|
url: `https://m.yohobuy.com/chanpin/${val}.html`,
|
|
|
changefreq: 'daily',
|
|
|
priority: 0.5
|
|
|
});
|
|
|
});
|
|
|
return pages;
|
|
|
}).timeout(200).catch(()=>{
|
|
|
return {};
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// m 地图数据
|
|
|
const mXmlData = (page) => {// eslint-disable-line
|
|
|
if (page > 1) {
|
|
|
return keywordsPage(page);
|
|
|
} else {
|
|
|
return Promise.all([keywordsPage(page),
|
|
|
getStaticUrls(_.get(staticUrls, 'm')),
|
|
|
itemXmlData()]).then(result => {
|
|
|
return _.concat(result[1], result[0], result[2]);
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
// list 地图数据
|
|
|
const listXmlData = () => {// eslint-disable-line
|
|
|
return getStaticUrls(_.get(staticUrls, 'list'));
|
...
|
...
|
@@ -95,7 +120,10 @@ const siteMap = (req, res, next) => { |
|
|
res.end('end');
|
|
|
return;
|
|
|
}
|
|
|
eval(subdomain + 'XmlData')().then(urls => {// eslint-disable-line
|
|
|
|
|
|
let page = req.params[0] || 1;
|
|
|
|
|
|
eval(subdomain + 'XmlData')(page).then(urls => {// eslint-disable-line
|
|
|
sm.createSitemap({
|
|
|
hostname: `https://${subdomain}.yohobuy.com`,
|
|
|
xmlNs: ' ',
|
...
|
...
|
|