Authored by 周少峰

sitemap pages

... ... @@ -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: ' ',
... ...
... ... @@ -46,6 +46,6 @@ router.get('/limitcodeColSize', help.limitcodeColSize);// 选择限购码颜色
router.get('/limitcodeIntro', help.limitcodeIntro);// 什么是限购码 (APP使用)
// 站点地图
router.get('/sitemap.xml', sitemap.siteMap);
router.get(/^\/sitemap(.*)\.xml/, sitemap.siteMap);
module.exports = router;
... ...
... ... @@ -51,9 +51,9 @@ module.exports = () => {
req.url = '/service/systemUpdate';
}
if (/^\/sitemap\.xml/.test(req.url)) {
if (/^\/sitemap(\d+)\.xml/.test(req.url)) {
// sitemap/sitemap.xml
req.url = '/service/sitemap.xml';
req.url = `/service${req.url}`;
}
if (/^\/coupon\/couponSend/.test(req.url)) {
... ...