diff --git a/docs/README.md b/docs/README.md index 32ef57c839..5ec89ce97d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2893,4 +2893,5 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看 ### 人人都是产品经理 + diff --git a/lib/router.js b/lib/router.js index 51486c2d12..2cba958341 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1021,6 +1021,7 @@ router.get('/jpmorganchase', require('./routes/jpmorganchase/research')); router.get('/meipai/user/:uid', require('./routes/meipai/user')); // 人人都是产品经理 +router.get('/woshipm/bookmarks/:id', require('./routes/woshipm/bookmarks')); router.get('/woshipm/user_article/:id', require('./routes/woshipm/user_article')); // 高清电台 diff --git a/lib/routes/woshipm/bookmarks.js b/lib/routes/woshipm/bookmarks.js new file mode 100644 index 0000000000..1a4ce10189 --- /dev/null +++ b/lib/routes/woshipm/bookmarks.js @@ -0,0 +1,47 @@ +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 remark_api = `http://www.woshipm.com/__api/v1/users/${id}/bookmarks`; + const response_api = await axios.get(remark_api); + const list = response_api.data.payload.value; + const out = await Promise.all( + list.map(async (info) => { + const title = info.title; + const date = info.date; + const itemUrl = info.permalink; + + 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, + }; +};