From c06806bc15787f645a96055e7db76a2ef95f9219 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 23 Aug 2020 04:03:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E7=88=B1Q=E7=94=9F=E6=B4=BB?= =?UTF-8?q?=E7=BD=91=20(#5498)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Henry Wang --- docs/other.md | 6 +++++ lib/router.js | 3 +++ lib/routes/iqshw/latest.js | 53 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 lib/routes/iqshw/latest.js diff --git a/docs/other.md b/docs/other.md index f3fc4ac2f..47ceb6437 100644 --- a/docs/other.md +++ b/docs/other.md @@ -55,6 +55,12 @@ pageClass: routes +## 爱 Q 生活网 + +### 最近更新 + + + ## BOOKSOURCE.STORE ### 书源仓库更新 diff --git a/lib/router.js b/lib/router.js index 7f436f50c..bbf412404 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3081,6 +3081,9 @@ router.get('/souyun/today', require('./routes/souyun/today')); // 生物谷 router.get('/bioon/latest', require('./routes/bioon/latest')); +// 爱Q生活网 +router.get('/iqshw/latest', require('./routes/iqshw/latest')); + // JustRun router.get('/justrun', require('./routes/justrun/index')); diff --git a/lib/routes/iqshw/latest.js b/lib/routes/iqshw/latest.js new file mode 100644 index 000000000..28eb7deac --- /dev/null +++ b/lib/routes/iqshw/latest.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.iqshw.com'; + const currentUrl = `${rootUrl}/post/new_100/`; + const response = await got({ + method: 'get', + url: currentUrl, + responseType: 'buffer', + }); + + const $ = cheerio.load(iconv.decode(response.data, 'gb2312')); + const list = $('ul.list-item li') + .slice(0, 15) + .map((_, item) => { + item = $(item); + const a = item.find('a'); + + return { + title: a.attr('title'), + link: rootUrl + a.attr('href'), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + responseType: 'buffer', + }); + + const content = cheerio.load(iconv.decode(detailResponse.data, 'gb2312')); + + item.pubDate = new Date(content('span.time').text() + ' GMT+8').toUTCString(); + item.description = content('div.content-intro').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: '爱Q生活网 - 最近更新', + link: currentUrl, + item: items, + }; +};