forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add 欢乐书客 (DIYgod#14591)
* feat(route): add 欢乐书客 * update radar * rm redundant code
- Loading branch information
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/chapter/:id': ['keocheung'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = (router) => { | ||
router.get('/chapter/:id', require('./chapter')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters