diff --git a/docs/README.md b/docs/README.md index d16f0afded..32ef57c839 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2890,3 +2890,7 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看 ### 加摩根大通研究所 + +### 人人都是产品经理 + + diff --git a/lib/router.js b/lib/router.js index 6747bf121e..51486c2d12 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1020,6 +1020,9 @@ router.get('/jpmorganchase', require('./routes/jpmorganchase/research')); // 美拍 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')); diff --git a/lib/routes/woshipm/user_article.js b/lib/routes/woshipm/user_article.js new file mode 100644 index 0000000000..f60acae4ff --- /dev/null +++ b/lib/routes/woshipm/user_article.js @@ -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, + }; +};