From bfa9f0e28a333dbaa81fbb34f7d8d508b58a07a3 Mon Sep 17 00:00:00 2001 From: Director Date: Thu, 19 Mar 2020 19:30:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0woshipm=E7=9A=84?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E6=96=87=E7=AB=A0=20(#4281)?= 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/latest.js | 45 ++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 lib/routes/woshipm/latest.js diff --git a/docs/new-media.md b/docs/new-media.md index 9513d7056..29f17ae8c 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -719,6 +719,10 @@ Supported sub-sites: +### 最新文章 + + + ## 少数派 sspai ### 最新上架付费专栏 diff --git a/lib/router.js b/lib/router.js index 336d0cbb9..105172450 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1208,6 +1208,7 @@ 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')); +router.get('/woshipm/latest', require('./routes/woshipm/latest')); // 高清电台 router.get('/gaoqing/latest', require('./routes/gaoqing/latest')); diff --git a/lib/routes/woshipm/latest.js b/lib/routes/woshipm/latest.js new file mode 100644 index 000000000..4ab62ce3b --- /dev/null +++ b/lib/routes/woshipm/latest.js @@ -0,0 +1,45 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const response_1 = await got('http://www.woshipm.com/__api/v1/stream-list'); + const response_2 = await got('http://www.woshipm.com/__api/v1/stream-list/page/2'); + const response_3 = await got('http://www.woshipm.com/__api/v1/stream-list/page/3'); + const payload = [...response_1.data.payload, ...response_2.data.payload, ...response_3.data.payload]; + const result = await Promise.all( + payload.map(async (item) => { + const title = item.title; + const link = item.permalink; + const guid = item.id; + const pubDate = new Date(item.date).toUTCString(); + + const single = { + title: title, + link: link, + guid: guid, + pubDate: pubDate, + description: '', + }; + + const key = 'woshipm' + guid; + 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 = $('.grap').html(); + + ctx.cache.set(key, single.description); + } + + return Promise.resolve(single); + }) + ); + ctx.state.data = { + title: '最新文章 - 人人都是产品经理', + link: 'http://www.woshipm.com/', + item: result, + }; +};