feat(route): add kakuyomu (#9371)

* feat(route): add kakuyomu

* feat(route): add kakuyomu

* add pubDate

* fix radar rule
This commit is contained in:
huangliangshusheng 2022-03-25 20:23:57 +08:00 committed by GitHub
parent f3618bb148
commit d1cda2a2be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 0 deletions

View File

@ -10,6 +10,16 @@ pageClass: routes
<RouteEn author="HenryQW" example="/allpoetry/newest" path="/allpoetry/:order?" :paramsDesc="['Ordering, `best` or `newest`, `best` by default']"/>
## kakuyomu
### episode
<RouteEn author="huangliangshusheng" example="/kakuyomu/episode/1177354054883783581" path="/kakuyomu/episode/:id" :paramsDesc="['Novel id, can be found in URL']">
Eg:<https://kakuyomu.jp/works/1177354054883783581>
</RouteEn>
## Literotica
### New Stories

View File

@ -10,6 +10,16 @@ pageClass: routes
<Route author="HenryQW" example="/allpoetry/newest" path="/allpoetry/:order?" :paramsDesc="['排序方式, `best``newest`, 缺省 `best`']"/>
## kakuyomu
### 章节更新
<Route author="huangliangshusheng" example="/kakuyomu/episode/1177354054883783581" path="/kakuyomu/episode/:id" :paramsDesc="['小说 id, 可在对应小说页 URL 中找到']">
举例网址:<https://kakuyomu.jp/works/1177354054883783581>
</Route>
## Kindle Unlimited
### 会员限时免费读书单

View File

@ -0,0 +1,54 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const id = ctx.params.id;
const limit = parseInt(ctx.query.limit) || 5;
const work_url = `https://kakuyomu.jp/works/${id}`;
const $ = cheerio.load(await get(work_url));
const work_title = $('#workTitle').text();
const introduction = $('#introduction').text();
const episode_list = $('a.widget-toc-episode-episodeTitle')
.map((_, episode) => {
const $_episode = $(episode);
return {
title: $_episode.find('span').text(),
link: $_episode.attr('href'),
pubDate: parseDate($_episode.find('time').attr('datetime')),
};
})
.toArray()
.sort((a, b) => (a.pubDate <= b.pubDate ? 1 : -1))
.slice(0, limit);
const item_list = await Promise.all(
episode_list.map((episode) =>
ctx.cache.tryGet(episode.link, async () => {
episode.link = `https://kakuyomu.jp${episode.link}`;
const content = cheerio.load(await get(episode.link));
episode.description = content('.widget-episodeBody').html();
return episode;
})
)
);
ctx.state.data = {
title: work_title,
link: work_url,
description: introduction,
language: 'ja',
item: item_list,
};
};
const get = async (url) => {
const response = await got({
method: 'get',
url,
});
return response.data;
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/episode/:id': ['huangliangshusheng'],
};

13
lib/v2/kakuyomu/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'kakuyomu.jp': {
_name: 'kakuyomu',
'.': [
{
title: '章节更新',
docs: 'https://docs.rsshub.app/reading.html#kakuyomu-zhang-jie-geng-xin',
source: ['/works/:id'],
target: '/kakuyomu/episode/:id',
},
],
},
};

View File

@ -0,0 +1 @@
module.exports = (router) => router.get('/episode/:id', require('./episode.js'));