feat: add 爱下电子书 (#3934)

This commit is contained in:
Jeason Lau
2020-02-09 19:44:48 +08:00
committed by GitHub
parent 986aba9eba
commit a365429e68
3 changed files with 51 additions and 0 deletions

View File

@@ -32,6 +32,12 @@ pageClass: routes
</Route> </Route>
## 爱下电子书
### 最新章节
<Route author="JeasonLau" example="/axdzs/191/191976" path="/axdzs/:id1/:id2" :paramsDesc="['小说网站链接倒数第二部分的数字, 可在对应小说页 URL 中找到', '小说网站链接最后的数字, 可在对应小说页 URL 中找到']" />
## 笔趣阁 ## 笔趣阁
### 小说更新 ### 小说更新

View File

@@ -2208,6 +2208,9 @@ router.get('/ifeng/feng/:id/:type', require('./routes/ifeng/feng'));
router.get('/open163/vip', require('./routes/netease/open/vip')); router.get('/open163/vip', require('./routes/netease/open/vip'));
router.get('/open163/latest', require('./routes/netease/open/latest')); router.get('/open163/latest', require('./routes/netease/open/latest'));
// 爱下电子书
router.get('/axdzs/:id1/:id2', require('./routes/novel/axdzs'));
// HackerOne // HackerOne
router.get('/hackerone/hacktivity', require('./routes/hackerone/hacktivity')); router.get('/hackerone/hacktivity', require('./routes/hackerone/hacktivity'));

42
lib/routes/novel/axdzs.js Normal file
View File

@@ -0,0 +1,42 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const baseUrl = 'https://read.aixdzs.com/';
module.exports = async (ctx) => {
const id1 = ctx.params.id1;
const id2 = ctx.params.id2;
const novelUrl = `${baseUrl}${id1}/${id2}/`;
const response = await got({
method: 'get',
url: novelUrl,
});
const data = response.data;
const $ = cheerio.load(data);
const title = $('h1').text();
const description = $('meta[name="description"]').attr('content');
const lastChapter = $('.chapter')
.last()
.children();
const chapterUrl = novelUrl + lastChapter.attr('href');
const chapterTitle = lastChapter.text();
const chapterContent = await ctx.cache.tryGet(chapterUrl, async () => {
const lastChapter = await got.get(chapterUrl);
const $ = cheerio.load(lastChapter.data);
return $('.content').html();
});
ctx.state.data = {
title: `爱下电子书-${title}`,
description: description,
link: novelUrl,
item: [
{
title: chapterTitle,
link: chapterUrl,
description: chapterContent,
},
],
};
};