From f64e1d6df259f3d70ed53b4f85dc3838ce1272de Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Fri, 24 May 2019 17:53:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E8=B5=B7=E7=82=B9=E7=BD=91?= =?UTF-8?q?=E9=99=90=E6=97=B6=E5=85=8D=E8=B4=B9=20(#2214)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/reading.md | 8 ++++++ lib/router.js | 2 ++ lib/routes/qidian/free-next.js | 45 ++++++++++++++++++++++++++++++++ lib/routes/qidian/free.js | 47 ++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 lib/routes/qidian/free-next.js create mode 100644 lib/routes/qidian/free.js diff --git a/docs/reading.md b/docs/reading.md index 4cbd96cb1..8295bb38a 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -78,6 +78,14 @@ pageClass: routes +### 限时免费 + + + +### 限时免费下期预告 + + + ## 青空文庫 ### 青空文庫新着リスト diff --git a/lib/router.js b/lib/router.js index 3cd677f56..0610968f9 100644 --- a/lib/router.js +++ b/lib/router.js @@ -372,6 +372,8 @@ router.get('/keep/user/:id', require('./routes/keep/user')); // 起点 router.get('/qidian/chapter/:id', require('./routes/qidian/chapter')); router.get('/qidian/forum/:id', require('./routes/qidian/forum')); +router.get('/qidian/free/:type?', require('./routes/qidian/free')); +router.get('/qidian/free-next/:type?', require('./routes/qidian/free-next')); // 纵横 router.get('/zongheng/chapter/:id', require('./routes/zongheng/chapter')); diff --git a/lib/routes/qidian/free-next.js b/lib/routes/qidian/free-next.js new file mode 100644 index 000000000..23da7677f --- /dev/null +++ b/lib/routes/qidian/free-next.js @@ -0,0 +1,45 @@ +const axios = require('@/utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const type = ctx.params.type; + + let link, title; + if (type === 'mm') { + link = 'https://www.qidian.com/mm/free'; + title = '起点女生网'; + } else { + link = 'https://www.qidian.com/free'; + title = '起点中文网'; + } + + const response = await axios({ + method: 'get', + url: link, + }); + const $ = cheerio.load(response.data); + + const list = $('div.other-rec-wrap li'); + const out = list + .map((index, item) => { + item = $(item); + + const img = ``; + const rank = `

评分:${item.find('.img-box span').text()}

`; + + return { + title: item.find('.book-info h4 a').text(), + description: img + rank + item.find('p.intro').html(), + link: 'https:' + item.find('.book-info h4 a').attr('href'), + author: item.find('p.author a').text(), + }; + }) + .get(); + + ctx.state.data = { + title: title, + description: `限时免费下期预告-${title}`, + link: link, + item: out, + }; +}; diff --git a/lib/routes/qidian/free.js b/lib/routes/qidian/free.js new file mode 100644 index 000000000..fc437ede0 --- /dev/null +++ b/lib/routes/qidian/free.js @@ -0,0 +1,47 @@ +const axios = require('@/utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const type = ctx.params.type; + + let link, title; + if (type === 'mm') { + link = 'https://www.qidian.com/mm/free'; + title = '起点女生网'; + } else { + link = 'https://www.qidian.com/free'; + title = '起点中文网'; + } + + const response = await axios({ + method: 'get', + url: link, + }); + const $ = cheerio.load(response.data); + + const list = $('#limit-list li'); + const out = list + .map((index, item) => { + item = $(item); + + const img = ``; + const rank = `

评分:${item.find('.score').text()}

`; + const update = ` a').attr('href')}>${item.find('p.update > a').text()}`; + + return { + title: item.find('.book-mid-info h4 a').text(), + description: img + rank + update + '
' + item.find('p.intro').html(), + pubDate: new Date(item.find('p.update span').text()).toUTCString(), + link: 'https:' + item.find('.book-mid-info h4 a').attr('href'), + author: item.find('p.author a.name').text(), + }; + }) + .get(); + + ctx.state.data = { + title: title, + description: `限时免费-${title}`, + link: link, + item: out, + }; +};