From bed9a34c99a494a64c8b59dbe785fa6698a95761 Mon Sep 17 00:00:00 2001 From: WenryXu Date: Thu, 19 Dec 2019 17:15:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=BA=BA=E4=BA=BA?= =?UTF-8?q?=E9=83=BD=E6=98=AF=E4=BA=A7=E5=93=81=E7=BB=8F=E7=90=86=20-=20?= =?UTF-8?q?=E5=A4=A9=E5=A4=A9=E9=97=AE=20(#3596)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 4 ++++ lib/router.js | 1 + lib/routes/woshipm/wen.js | 45 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 lib/routes/woshipm/wen.js diff --git a/docs/new-media.md b/docs/new-media.md index 0aa980891f..707ebd59a4 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -618,6 +618,10 @@ pageClass: routes +### 天天问 + + + ### 用户收藏 diff --git a/lib/router.js b/lib/router.js index a3a0037348..2f21208e05 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1133,6 +1133,7 @@ router.get('/dockerhub/build/:owner/:image/:tag?', require('./routes/dockerhub/b // 人人都是产品经理 router.get('/woshipm/popular', require('./routes/woshipm/popular')); +router.get('/woshipm/wen', require('./routes/woshipm/wen')); 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/wen.js b/lib/routes/woshipm/wen.js new file mode 100644 index 0000000000..ad3951d11d --- /dev/null +++ b/lib/routes/woshipm/wen.js @@ -0,0 +1,45 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const response = await got('https://wen.woshipm.com/m/main/indexNewData.html'); + const $ = cheerio.load(response.data); + const postList = $('.article-list-item').get(); + const result = await Promise.all( + postList.map(async (item) => { + const title = $(item) + .find('.went-head-text') + .text(); + const link = + 'https://wen.woshipm.com/' + + $(item) + .find('.went-head') + .attr('href'); + const pubDate = new Date().toUTCString(); + + const single = { + title: title, + link: link, + guid: link, + pubDate: pubDate, + description: '', + }; + + const key = link; + const value = await ctx.cache.get(key); + + if (value) { + single.description = value; + } else { + const temp = await got(link); + const $ = cheerio.load(temp.data); + single.description = $('.wt-desc').html(); + + ctx.cache.set(key, single.description); + } + + return Promise.resolve(single); + }) + ); + ctx.state.data = { title: '天天问 - 人人都是产品经理', link: 'http://wen.woshipm.com/', item: result }; +};