Authored by 陈峰

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

... ... @@ -7,6 +7,9 @@
const mRoot = '../models';
const rssModel = require(`${mRoot}/rss`);
const Feed = require('feed');
const _ = require('lodash');
const moment = require('moment');
const helpers = global.yoho.helpers;
/**
... ... @@ -15,18 +18,40 @@ const helpers = global.yoho.helpers;
const index = (req, res, next) => {
let gender = req.query.gender || '1,2,3',
items = [];
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
return rssModel.getRssArticle(gender).then((result) => {
return res.render('rss/index', {
layout: false,
time: (new Date()).toUTCString(),
items: result
if (!result) {
return next();
}
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
var feed = new Feed({
id: 'http://yohobuy.com',
title: '有货逛',
description: 'Yoho!Buy有货 | 年轻人潮流购物中心',
link: 'http://yohobuy.com',
copyright: '2015 yoho.inc',
generator: 'http://m.yohobuy.com',
updated: new Date(),
})
_.forEach(result, item => {
item.url = item.url.indexOf('http') > 0 ? item.url : 'http://'+item.url
feed.addItem({
title: item.title,
link: `${item.url}&ref=rss`,
description: item.intro,
author: [{
name: (item.author && item.author.name) || ' '
}],
date: new Date(item.publishTimeLong && parseFloat(item.publishTimeLong) || moment(item.publishTime, "MM月DD日 HH:mm"))
});
});
if (req.params[0] && req.params[0] === '/atom') {
return res.send(feed.render('atom-1.0'));
}
return res.send(feed.render('rss-2.0'))
});
};
module.exports = {
index
};
};
\ No newline at end of file
... ...
... ... @@ -44,7 +44,8 @@ const getRssArticle = (gender) => {
if (typeof value.id !== 'undefined') {
build = guangProcess.formatArticle(value, false, false, true);
build.author.name = (build.author && build.author.name) || '';
build.author = build.author || {};
build.author.name = (build.author && build.author.name) || ''
return _genIntro(value.id).then((intro) => {
build.intro = intro;
result.push(build);
... ...
... ... @@ -54,7 +54,7 @@ router.get('/plustar', plustar.getListData); // 国际优选列表页
router.get('/plustar/brandinfo', plustar.getDetailData); // 国际优选详情页
router.post('/plustar/brandinfoAsync', plustar.getDetailDataAsync); // 国际优选详情页异步数据
router.get('/rss', rss.index); // 订阅资讯
router.get(/^\/rss(\/\w+)?(\/\w+)?/, rss.index); // 订阅资讯
router.get('/info/listData', index.listDynamicData);
router.get('/info/detailData', index.detailDynamicData);
... ...
... ... @@ -83,7 +83,7 @@ module.exports = {
port: '4444' // influxdb port
},
console: {
level: 'debug',
level: 'error',
colorize: 'all',
prettyPrint: true
}
... ...
{
"name": "m-yohobuy-node",
"version": "5.1.5",
"version": "5.1.6",
"private": true,
"description": "A New Yohobuy Project With Express",
"repository": {
... ... @@ -26,6 +26,7 @@
"cookie-parser": "^1.4.3",
"cookie-session": "^1.2.0",
"express": "^4.14.0",
"feed": "^0.3.0",
"lodash": "^4.16.1",
"md5": "^2.1.0",
"moment": "^2.15.1",
... ...
... ... @@ -6,7 +6,6 @@
background: #fff;
box-sizing: border-box;
overflow: hidden;
background: #fff;
margin-bottom: 30px;
li {
... ... @@ -33,6 +32,7 @@
.shop-area {
background: #fff;
border-bottom: 1px solid #e0e0e0;
min-width: 750px;
}
}
... ...
... ... @@ -68,6 +68,7 @@ const formatArticle = (articleData, showTag, isApp, showAuthor, uid, reqQueryStr
title: articleData.title,
text: articleData.intro,
publishTime: articleData.publish_time,
publishTimeLong: articleData.publish_time_long,
pageView: articleData.views_num
};
... ...