Authored by 郝肖肖

'sitemap-guang-news'

... ... @@ -8,6 +8,7 @@ const staticUrls = require('../../../config/staticUrls');
const api = global.yoho.API;
const Service = global.yoho.ServiceAPI;
const headerModel = require('../../../doraemon/models/header');
const siteMapService = require('../models/site-map-service');
const redis = global.yoho.redis;
... ... @@ -156,6 +157,44 @@ const siteMap = (req, res, next) => {
}).catch(next);
};
const _createSitemap = (req, res, rdata, startUrl, endUrl) => {
sm.createSitemap({
hostname: 'https://www.yohobuy.com',
xmlNs: ' ',
urls: _.map(rdata, id => {
return {
url: `${startUrl}${id}${endUrl}`,
changefreq: 'daily',
priority: 0.3
};
})
}).toXML(function(err, xml) {
rdata = [];
if (err) {
return res.status(500).end();
}
res.header('Content-Type', 'application/xml');
res.send(xml);
});
};
const guangMap = (req, res, next) => {
req.ctx(siteMapService).guangList(1, []).then(rdata => {
return _createSitemap(req, res, rdata, 'https://www.yohobuy.com/guang/', '.html');
}).catch(next);
};
const newsMap = (req, res, next) => {
req.ctx(siteMapService).newsList(1, []).then(rdata => {
return _createSitemap(req, res, rdata, 'https://www.yohobuy.com/news/', '.html');
}).catch(next);
};
module.exports = {
siteMap
siteMap,
guangMap,
newsMap
};
... ...
/**
* map
* @author: xiaoxiao<xiaoxiao.hao@yoho.cn>
* @date: 2017/10/24
*/
'use strict';
const _ = require('lodash');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
guangList(page, lres) {
return this.get({
url: 'guang/api/v2/article/getList',
data: {
page: page,
limit: 1000
},
param: {
cache: true
},
api: global.yoho.ServiceAPI
}).then(rdata => {
let artList = _.get(rdata, 'data.list.artList', []);
if (artList.length <= 0) {
return lres;
}
lres = lres.concat(_.map(artList, (art) => {
return art.id;
}));
rdata = [];
artList = [];
return this.guangList(++page, lres);
});
}
newsList(page, lres) {
return this.get({
url: 'yohonow/api/page/getPolymerizationList',
data: {
type: 'wechat',
limit: 100,
id: 'yohobuy4008899646,yohogroup,YOHO_GIRL,mars-app',
page: page
},
param: {
cache: true
},
api: global.yoho.YohoNowApi
}).then(rdata => {
let artList = _.get(rdata, 'data.content', []);
if (artList.length <= 0) {
return lres;
}
lres = lres.concat(_.map(artList, (art) => {
return `${art.id}_${art.cid}`;
}));
rdata = [];
artList = [];
return this.newsList(++page, lres);
});
}
};
... ...
... ... @@ -31,6 +31,6 @@ router.post('/common/getNewArrival', channelController.getNewArrival);
router.get('/guide', channelController.getIndexGuide);
// www站点地图
router.get(/\/sitemap(\d*)\.xml/, sitemap.siteMap);
router.get(/^\/sitemap(\d*)\.xml/, sitemap.siteMap);
module.exports = router;
... ...
... ... @@ -30,7 +30,7 @@ router.get('/info/detailData', guangController.detailDynamicData);
// router.get('/info/commentData', guangController.detailCommentData);
// guang站点地图
router.get('/sitemap.xml', sitemap.siteMap);
// seo-站点地图
router.get('/sitemap.xml', sitemap.guangMap);
module.exports = router;
... ...
... ... @@ -10,10 +10,13 @@ const router = require('express').Router(); // eslint-disable-line
const cRoot = './controllers';
const newsController = require(`${cRoot}/index`);
const sitemap = require('../3party/controllers/sitemap');
router.get(['/', '/index/index'], newsController.index);
router.get(/\/([\d]+)_([\d]+).html/, newsController.detail);
// seo-站点地图
router.get('/sitemap.xml', sitemap.newsMap);
// ajax
... ...