Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add kakuyomu #9371

Merged
merged 7 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ pageClass: routes

<Route author="HenryQW" example="/allpoetry/newest" path="/allpoetry/:order?" :paramsDesc="['排序方式, `best` 或 `newest`, 缺省 `best`']"/>

## kakuyomu

### 章节
TonyRL marked this conversation as resolved.
Show resolved Hide resolved

<Route author="huangliangshusheng" example="/kakuyomu/episode/1177354054883783581" path="/kakuyomu/episode/:id" :paramsDesc="['小说 id, 可在对应小说页 URL 中找到']">

举例网址:<https://kakuyomu.jp/works/1177354054883783581>

</Route>
TonyRL marked this conversation as resolved.
Show resolved Hide resolved
## Kindle Unlimited

### 会员限时免费读书单
Expand Down
51 changes: 51 additions & 0 deletions lib/v2/kakuyomu/episode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const id = ctx.params.id;
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')
.slice(-5)
.map((_, episode) => {
const $_episode = $(episode);
return {
title: $_episode.find('span').text(),
link: $_episode.attr('href'),
TonyRL marked this conversation as resolved.
Show resolved Hide resolved
};
})
.toArray()
.reverse();

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;
};
3 changes: 3 additions & 0 deletions lib/v2/kakuyomu/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/episode/:id': ['huangliangshusheng'],
};
13 changes: 13 additions & 0 deletions lib/v2/kakuyomu/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'kakuyomu.jp': {
_name: 'kakuyomu',
'.': [
{
title: '章节',
docs: 'https://docs.rsshub.app/reading.html#kakuyomu-zhang-jie',
source: ['/works/:id'],
target: '/kakuyomu/episode/:id',
},
],
},
};
1 change: 1 addition & 0 deletions lib/v2/kakuyomu/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = (router) => router.get('/episode/:id', require('./episode.js'));