feat: add 起点网限时免费 (#2214)

This commit is contained in:
Chenyang Shi
2019-05-24 17:53:15 +08:00
committed by DIYgod
parent 8888da3fc5
commit f64e1d6df2
4 changed files with 102 additions and 0 deletions

View File

@@ -78,6 +78,14 @@ pageClass: routes
<Route author="Chingyat" example="/qidian/forum/1010400217" path="/qidian/forum/:id" :paramsDesc="['小说 id, 可在对应小说页 URL 中找到']"/>
### 限时免费
<Route author="LogicJake" example="/qidian/free" path="/qidian/free/:type?" :paramsDesc="['默认不填为起点中文网,填 mm 为起点女生网']"/>
### 限时免费下期预告
<Route author="LogicJake" example="/qidian/free-next" path="/qidian/free-next/:type?" :paramsDesc="['默认不填为起点中文网,填 mm 为起点女生网']"/>
## 青空文庫
### 青空文庫新着リスト

View File

@@ -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'));

View File

@@ -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 = `<img referrerpolicy="no-referrer" src="https:${item.find('.img-box img').attr('src')}">`;
const rank = `<p>评分:${item.find('.img-box span').text()}</p>`;
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,
};
};

47
lib/routes/qidian/free.js Normal file
View File

@@ -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 = `<img referrerpolicy="no-referrer" src="https:${item.find('.book-img-box img').attr('src')}">`;
const rank = `<p>评分:${item.find('.score').text()}</p>`;
const update = `<a href=https:${item.find('p.update > a').attr('href')}>${item.find('p.update > a').text()}</a>`;
return {
title: item.find('.book-mid-info h4 a').text(),
description: img + rank + update + '<br>' + 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,
};
};