feat(route): add hameln (#9429)
* feat(route): add hameln * feat(route): add hameln * fix doc * Update lib/v2/hameln/chapter.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * add timezone Co-authored-by: Tony <TonyRL@users.noreply.github.com>
This commit is contained in:
parent
215db34f02
commit
c6fbc9ecf2
|
|
@ -10,6 +10,16 @@ pageClass: routes
|
|||
|
||||
<RouteEn author="HenryQW" example="/allpoetry/newest" path="/allpoetry/:order?" :paramsDesc="['Ordering, `best` or `newest`, `best` by default']"/>
|
||||
|
||||
## hameln
|
||||
|
||||
### chapter
|
||||
|
||||
<RouteEn author="huangliangshusheng" example="/hameln/chapter/264928" path="/hameln/chapter/:id" :paramsDesc="['Novel id, can be found in URL']">
|
||||
|
||||
Eg:<https://syosetu.org/novel/264928/>
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## kakuyomu
|
||||
|
||||
### episode
|
||||
|
|
|
|||
|
|
@ -10,6 +10,16 @@ pageClass: routes
|
|||
|
||||
<Route author="HenryQW" example="/allpoetry/newest" path="/allpoetry/:order?" :paramsDesc="['排序方式, `best` 或 `newest`, 缺省 `best`']"/>
|
||||
|
||||
## hameln
|
||||
|
||||
### 章节更新
|
||||
|
||||
<Route author="huangliangshusheng" example="/hameln/chapter/264928" path="/hameln/chapter/:id" :paramsDesc="['小说 id, 可在对应小说页 URL 中找到']">
|
||||
|
||||
举例网址:<https://syosetu.org/novel/264928/>
|
||||
|
||||
</Route>
|
||||
|
||||
## kakuyomu
|
||||
|
||||
### 章节更新
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const limit = parseInt(ctx.query.limit) || 5;
|
||||
const link = `https://syosetu.org/novel/${id}`;
|
||||
const $ = cheerio.load(await get(link));
|
||||
|
||||
const title = $('span[itemprop="name"]').text();
|
||||
const description = $('div.ss:nth-child(2)').text();
|
||||
|
||||
const chapter_list = $('tr[bgcolor]')
|
||||
.map((_, chapter) => {
|
||||
const $_chapter = $(chapter);
|
||||
const chapter_link = $_chapter.find('a');
|
||||
return {
|
||||
title: chapter_link.text(),
|
||||
link: chapter_link.attr('href'),
|
||||
pubDate: timezone(parseDate($_chapter.find('nobr').text(), 'YYYYMMDD HH:mm'), +9),
|
||||
};
|
||||
})
|
||||
.toArray()
|
||||
.sort((a, b) => (a.pubDate <= b.pubDate ? 1 : -1))
|
||||
.slice(0, limit);
|
||||
|
||||
const item_list = await Promise.all(
|
||||
chapter_list.map((chapter) => {
|
||||
chapter.link = `${link}/${chapter.link}`;
|
||||
return ctx.cache.tryGet(chapter.link, async () => {
|
||||
const content = cheerio.load(await get(chapter.link));
|
||||
chapter.description = content('#honbun').html();
|
||||
return chapter;
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title,
|
||||
description,
|
||||
link,
|
||||
language: 'ja',
|
||||
item: item_list,
|
||||
};
|
||||
};
|
||||
|
||||
const get = async (url) => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url,
|
||||
headers: {
|
||||
cookie: 'over18=off',
|
||||
},
|
||||
});
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/chapter/:id': ['huangliangshusheng'],
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'syosetu.org': {
|
||||
_name: 'hameln',
|
||||
'.': [
|
||||
{
|
||||
title: '章节更新',
|
||||
docs: 'https://docs.rsshub.app/reading.html#hameln-zhang-jie-geng-xin',
|
||||
source: ['/novel/:id'],
|
||||
target: '/hameln/chapter/:id',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1 @@
|
|||
module.exports = (router) => router.get('/chapter/:id', require('./chapter.js'));
|
||||
Loading…
Reference in New Issue