add 人人都是产品经理专栏作者文章 (#1532)

This commit is contained in:
Chenyang Shi
2019-02-13 12:10:47 +08:00
committed by DIYgod
parent a278da1d8e
commit fd70841e63
3 changed files with 70 additions and 0 deletions

View File

@@ -2890,3 +2890,7 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
### 加摩根大通研究所 ### 加摩根大通研究所
<route name="新闻" author="howel.52" example="/jpmorganchase" path="/jpmorganchase"/> <route name="新闻" author="howel.52" example="/jpmorganchase" path="/jpmorganchase"/>
### 人人都是产品经理
<route name="用户文章" author="LogicJake" example="/woshipm/user_article/324696" path="/woshipm/user_article/:id" :paramsDesc="['用户id']"/>

View File

@@ -1020,6 +1020,9 @@ router.get('/jpmorganchase', require('./routes/jpmorganchase/research'));
// 美拍 // 美拍
router.get('/meipai/user/:uid', require('./routes/meipai/user')); router.get('/meipai/user/:uid', require('./routes/meipai/user'));
// 人人都是产品经理
router.get('/woshipm/user_article/:id', require('./routes/woshipm/user_article'));
// 高清电台 // 高清电台
router.get('/gaoqing/latest', require('./routes/gaoqing/latest')); router.get('/gaoqing/latest', require('./routes/gaoqing/latest'));

View File

@@ -0,0 +1,63 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id;
const link = `http://www.woshipm.com/u/${id}`;
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const name = $('div.name').text();
const list = $('div.postlist-item.u-clearfix div.content')
.slice(0, 10)
.map(function() {
const info = {
title: $(this)
.find('h2.post-title a')
.attr('title'),
link: $(this)
.find('h2.post-title a')
.attr('href'),
date: $(this)
.find('time')
.text(),
};
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const date = info.date;
const itemUrl = info.link;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const description = $('div.grap')
.html()
.trim();
const single = {
title: title,
link: itemUrl,
description: description,
pubDate: new Date(date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `${name}的文章-人人都是产品经理`,
link: link,
item: out,
};
};