feat : add PMCAFF 今日推荐/精选 RSS (#3405)

This commit is contained in:
Jeason0228
2019-11-11 12:15:00 +08:00
committed by DIYgod
parent ba8070b1b2
commit 2583be6834
3 changed files with 74 additions and 0 deletions

View File

@@ -131,6 +131,12 @@ pageClass: routes
<Route author="emdoe" example="/nautilus/topic/Art" path="/nautilus/topic/:tid" :paramsDesc="['话题 id, 可在页面上方 TOPICS 栏目处找到']"/>
## PMCAFF
### 今日推荐/精选
<Route author="Jeason0228" example="/pmcaff/list/2" path="/pmcaff/list/:typeid" :paramsDesc="['分类 id,1=今天推荐,2=精选']"/>
## Readhub
### 分类

View File

@@ -1034,6 +1034,9 @@ router.get('/tingdiantz/nanjing', require('./routes/tingdiantz/nanjing'));
router.get('/36kr/search/article/:keyword', require('./routes/36kr/search/article'));
router.get('/36kr/newsflashes', require('./routes/36kr/newsflashes'));
// PMCAFF
router.get('/pmcaff/list/:typeid', require('./routes/pmcaff/list'));
// icourse163
router.get('/icourse163/newest', require('./routes/icourse163/newest'));

65
lib/routes/pmcaff/list.js Normal file
View File

@@ -0,0 +1,65 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const map = new Map([['1', { name: '今日推荐' }], ['2', { name: '精选' }]]);
module.exports = async (ctx) => {
const typeid = ctx.params.typeid || '2';
const OutName = map.get(typeid).name;
const url = `https://coffee.pmcaff.com/list?type=${typeid}`;
const response = await got({
method: 'post',
url: `https://coffee.pmcaff.com/list`,
headers: {
Referer: url,
},
json: true,
data: {
page: 1,
feed_sum: 15,
type: typeid,
times: 0,
user_id: 0,
},
});
const list = response.data.data;
// console.log(list.length);
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const date = info.created_at;
const id = info.id;
const author = info.author;
const itemUrl = `https://coffee.pmcaff.com/article/${id}`;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got({
method: 'get',
url: itemUrl,
headers: {
Referer: url,
},
});
const data = response.data;
const $ = cheerio.load(data);
$('#articleCont img').attr('referrerpolicy', 'no-referrer');
const description = $('#articleCont').html();
const single = {
title: title,
author,
link: itemUrl,
description: description,
pubDate: new Date(date + ' GMT').toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `${OutName}-PMCAFF互联网产品社区`,
description: `PMCAFF互联网产品社区 - 产品经理人气组织::专注于互联网产品研究`,
link: url,
item: out,
};
};