Authored by 陈峰

Merge branch 'hotfix/rss-format' into release/5.2

@@ -7,6 +7,9 @@ @@ -7,6 +7,9 @@
7 7
8 const mRoot = '../models'; 8 const mRoot = '../models';
9 const rssModel = require(`${mRoot}/rss`); 9 const rssModel = require(`${mRoot}/rss`);
  10 +const Feed = require('feed');
  11 +const _ = require('lodash');
  12 +const moment = require('moment');
10 const helpers = global.yoho.helpers; 13 const helpers = global.yoho.helpers;
11 14
12 /** 15 /**
@@ -15,18 +18,40 @@ const helpers = global.yoho.helpers; @@ -15,18 +18,40 @@ const helpers = global.yoho.helpers;
15 const index = (req, res, next) => { 18 const index = (req, res, next) => {
16 let gender = req.query.gender || '1,2,3', 19 let gender = req.query.gender || '1,2,3',
17 items = []; 20 items = [];
18 -  
19 - res.setHeader('Content-Type', 'text/xml; charset=utf-8');  
20 return rssModel.getRssArticle(gender).then((result) => { 21 return rssModel.getRssArticle(gender).then((result) => {
21 - return res.render('rss/index', {  
22 - layout: false,  
23 - time: (new Date()).toUTCString(),  
24 - items: result 22 + if (!result) {
  23 + return next();
  24 + }
  25 + res.setHeader('Content-Type', 'text/xml; charset=utf-8');
  26 + var feed = new Feed({
  27 + id: 'http://yohobuy.com',
  28 + title: '有货逛',
  29 + description: 'Yoho!Buy有货 | 年轻人潮流购物中心',
  30 + link: 'http://yohobuy.com',
  31 + copyright: '2015 yoho.inc',
  32 + generator: 'http://m.yohobuy.com',
  33 + updated: new Date(),
  34 + })
  35 + _.forEach(result, item => {
  36 + item.url = item.url.indexOf('http') > 0 ? item.url : 'http://'+item.url
  37 + feed.addItem({
  38 + title: item.title,
  39 + link: `${item.url}&ref=rss`,
  40 + description: item.intro,
  41 + author: [{
  42 + name: (item.author && item.author.name) || ' '
  43 + }],
  44 + date: new Date(item.publishTimeLong && parseFloat(item.publishTimeLong) || moment(item.publishTime, "MM月DD日 HH:mm"))
  45 + });
25 }); 46 });
  47 + if (req.params[0] && req.params[0] === '/atom') {
  48 + return res.send(feed.render('atom-1.0'));
  49 + }
  50 + return res.send(feed.render('rss-2.0'))
26 }); 51 });
27 }; 52 };
28 53
29 54
30 module.exports = { 55 module.exports = {
31 index 56 index
32 -}; 57 +};
@@ -44,7 +44,8 @@ const getRssArticle = (gender) => { @@ -44,7 +44,8 @@ const getRssArticle = (gender) => {
44 44
45 if (typeof value.id !== 'undefined') { 45 if (typeof value.id !== 'undefined') {
46 build = guangProcess.formatArticle(value, false, false, true); 46 build = guangProcess.formatArticle(value, false, false, true);
47 - build.author.name = (build.author && build.author.name) || ''; 47 + build.author = build.author || {};
  48 + build.author.name = (build.author && build.author.name) || ''
48 return _genIntro(value.id).then((intro) => { 49 return _genIntro(value.id).then((intro) => {
49 build.intro = intro; 50 build.intro = intro;
50 result.push(build); 51 result.push(build);
@@ -54,7 +54,7 @@ router.get('/plustar', plustar.getListData); // 国际优选列表页 @@ -54,7 +54,7 @@ router.get('/plustar', plustar.getListData); // 国际优选列表页
54 router.get('/plustar/brandinfo', plustar.getDetailData); // 国际优选详情页 54 router.get('/plustar/brandinfo', plustar.getDetailData); // 国际优选详情页
55 router.post('/plustar/brandinfoAsync', plustar.getDetailDataAsync); // 国际优选详情页异步数据 55 router.post('/plustar/brandinfoAsync', plustar.getDetailDataAsync); // 国际优选详情页异步数据
56 56
57 -router.get('/rss', rss.index); // 订阅资讯 57 +router.get(/^\/rss(\/\w+)?(\/\w+)?/, rss.index); // 订阅资讯
58 58
59 router.get('/info/listData', index.listDynamicData); 59 router.get('/info/listData', index.listDynamicData);
60 router.get('/info/detailData', index.detailDynamicData); 60 router.get('/info/detailData', index.detailDynamicData);
@@ -83,7 +83,7 @@ module.exports = { @@ -83,7 +83,7 @@ module.exports = {
83 port: '4444' // influxdb port 83 port: '4444' // influxdb port
84 }, 84 },
85 console: { 85 console: {
86 - level: 'debug', 86 + level: 'error',
87 colorize: 'all', 87 colorize: 'all',
88 prettyPrint: true 88 prettyPrint: true
89 } 89 }
1 { 1 {
2 "name": "m-yohobuy-node", 2 "name": "m-yohobuy-node",
3 - "version": "5.1.5", 3 + "version": "5.1.6",
4 "private": true, 4 "private": true,
5 "description": "A New Yohobuy Project With Express", 5 "description": "A New Yohobuy Project With Express",
6 "repository": { 6 "repository": {
@@ -26,6 +26,7 @@ @@ -26,6 +26,7 @@
26 "cookie-parser": "^1.4.3", 26 "cookie-parser": "^1.4.3",
27 "cookie-session": "^1.2.0", 27 "cookie-session": "^1.2.0",
28 "express": "^4.14.0", 28 "express": "^4.14.0",
  29 + "feed": "^0.3.0",
29 "lodash": "^4.16.1", 30 "lodash": "^4.16.1",
30 "md5": "^2.1.0", 31 "md5": "^2.1.0",
31 "moment": "^2.15.1", 32 "moment": "^2.15.1",
@@ -6,7 +6,6 @@ @@ -6,7 +6,6 @@
6 background: #fff; 6 background: #fff;
7 box-sizing: border-box; 7 box-sizing: border-box;
8 overflow: hidden; 8 overflow: hidden;
9 - background: #fff;  
10 margin-bottom: 30px; 9 margin-bottom: 30px;
11 10
12 li { 11 li {
@@ -33,6 +32,7 @@ @@ -33,6 +32,7 @@
33 .shop-area { 32 .shop-area {
34 background: #fff; 33 background: #fff;
35 border-bottom: 1px solid #e0e0e0; 34 border-bottom: 1px solid #e0e0e0;
  35 + min-width: 750px;
36 } 36 }
37 } 37 }
38 38
@@ -68,6 +68,7 @@ const formatArticle = (articleData, showTag, isApp, showAuthor, uid, reqQueryStr @@ -68,6 +68,7 @@ const formatArticle = (articleData, showTag, isApp, showAuthor, uid, reqQueryStr
68 title: articleData.title, 68 title: articleData.title,
69 text: articleData.intro, 69 text: articleData.intro,
70 publishTime: articleData.publish_time, 70 publishTime: articleData.publish_time,
  71 + publishTimeLong: articleData.publish_time_long,
71 pageView: articleData.views_num 72 pageView: articleData.views_num
72 }; 73 };
73 74