Skip to content

Commit

Permalink
feat(route): add 欢乐书客 (DIYgod#14591)
Browse files Browse the repository at this point in the history
* feat(route): add 欢乐书客

* update radar

* rm redundant code
  • Loading branch information
keocheung authored Feb 28, 2024
1 parent 09cf6db commit e41ed0c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
46 changes: 46 additions & 0 deletions lib/v2/hbooker/chapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const { id } = ctx.params;
const limit = Number.parseInt(ctx.query.limit) || 10;

const baseUrl = 'https://www.hbooker.com';

const { data: response } = await got(`${baseUrl}/book/${id}?arr_reverse=1`);
const $ = cheerio.load(response);

const list = $('div.book-chapter-list ul li a')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
});
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);

const rawDate = $('div.read-hd p span').eq(2).text();
item.pubDate = timezone(parseDate(rawDate.replace('更新时间:', '')), +8);

return item;
})
)
);

ctx.state.data = {
title: `欢乐书客 ${$('div.book-title h1').text()}`,
link: `${baseUrl}/book/${id}`,
description: $('div.book-desc').text(),
image: $('div.book-cover img').attr('src'),
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/hbooker/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/chapter/:id': ['keocheung'],
};
13 changes: 13 additions & 0 deletions lib/v2/hbooker/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'hbooker.com': {
_name: '欢乐书客',
'.': [
{
title: '章节',
docs: 'https://docs.rsshub.app/routes/reading#huan-le-shu-ke',
source: '/book/:id',
target: '/hbooker/chapter/:id',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/hbooker/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/chapter/:id', require('./chapter'));
};
6 changes: 6 additions & 0 deletions website/docs/routes/reading.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@

<Route author="junbaor" example="/enclavebooks/collection/103702" path="/enclavebooks/collection/:uid" paramsDesc={['用户ID, 自行抓包寻找']} />

## 欢乐书客 {#huan-le-shu-ke}

### 章节 {#huan-le-shu-ke-zhang-jie}

<Route author="keocheung" example="/hbooker/chapter/100113279" path="/hbooker/chapter/:id" paramsDesc={['小说 id, 可在对应小说页 URL 中找到']} radar="1" />

## 晋江文学城 {#jin-jiang-wen-xue-cheng}

### 作者最新作品 {#jin-jiang-wen-xue-cheng-zuo-zhe-zui-xin-zuo-pin}
Expand Down

0 comments on commit e41ed0c

Please sign in to comment.