diff --git a/docs/reading.md b/docs/reading.md index 0c013eabef..7d16dec71e 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -129,3 +129,13 @@ pageClass: routes ### 主页 + +## 书趣阁 + +### 小说更新 + + + +举例网址:http://www.shuquge.com/txt/8659/index.html + + diff --git a/lib/router.js b/lib/router.js index ecf71c30ef..5e1b167ab6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -504,6 +504,7 @@ router.get('/novel/biquge/:id', require('./routes/novel/biquge')); router.get('/novel/uukanshu/:uid', require('./routes/novel/uukanshu')); router.get('/novel/wenxuemi/:id1/:id2', require('./routes/novel/wenxuemi')); router.get('/novel/booksky/:id', require('./routes/novel/booksky')); +router.get('/novel/shuquge/:id', require('./routes/novel/shuquge')); // 中国气象网 router.get('/weatheralarm', require('./routes/weatheralarm')); diff --git a/lib/routes/novel/shuquge.js b/lib/routes/novel/shuquge.js new file mode 100644 index 0000000000..b4641b9fd7 --- /dev/null +++ b/lib/routes/novel/shuquge.js @@ -0,0 +1,68 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +const baseUrl = 'http://www.shuquge.com/txt/'; +// 获取小说的最新章节列表 +module.exports = async (ctx) => { + const id = ctx.params.id; // 小说id + + const response = await got({ + method: 'get', + url: `${baseUrl}${id}/index.html`, + // responseEncoding: 'gbk', //该配置项在 0.18版本中没有打包进去 + responseType: 'buffer', + }); + const responseHtml = iconv.decode(response.data, 'utf-8'); + const $ = cheerio.load(responseHtml); + const title = $('.listmain>dl>dt') + .eq(0) + .text(); + const description = $('.intro').text(); + const cover_url = $('.cover>img') + .eq(0) + .attr('src'); + const list = $('.listmain dd').slice(0, 9); + const chapter_item = list + .find('a') + .map((_, e) => ({ + title: e.children[0].data, + link: e.attribs.href, + })) + .get(); + + const items = await Promise.all( + chapter_item.map(async (item) => { + const cache = await ctx.cache.get(item.link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await got({ + method: 'get', + url: `${baseUrl}${id}/${item.link}`, + responseType: 'buffer', + }); + + const responseHtml = iconv.decode(response.data, 'utf-8'); + const $ = cheerio.load(responseHtml); + + const description = $('#content').html(); + + const single = { + title: item.title, + description, + link: item.link, + }; + ctx.cache.set(item.link, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + ctx.state.data = { + title: `笔趣阁 ${title}`, + link: `${baseUrl}${id}/index.html`, + image: cover_url, + description: description, + item: items, + }; +};