feat(route): add route Inoreader (#11899)

* add route inoreader

* use query param limit & modify docs & modify radar

* Update lib/v2/inoreader/radar.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* add pubDate

* Update lib/v2/inoreader/index.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

---------
This commit is contained in:
BeautyyuYanli
2023-02-20 20:56:37 +08:00
committed by GitHub
co-authored by Tony
parent d6a13dc24b
commit 4f1cdf6a84
6 changed files with 100 additions and 0 deletions
+16
View File
@@ -20,6 +20,22 @@ Eg:<https://syosetu.org/novel/264928/>
</RouteEn>
## Inoreader
### HTML Clip
<RouteEn author="BeautyyuYanli" example="/inoreader/html_clip/1006346356/News?limit=3" path="/html_clip/:user/:tag" :paramsDesc="[
'user id, the interger after user/ in the example URL',
'tag, the string after tag/ in the example URL',
]">
Use query parameter `limit=n` to limit the number of articles, default to 20
Eg: <https://www.inoreader.com/stream/user/1006346356/tag/News/view/html?n=3>
</RouteEn>
## kakuyomu
### episode
+15
View File
@@ -20,6 +20,21 @@ pageClass: routes
</Route>
## Inoreader
### HTML Clip
<Route author="BeautyyuYanli" example="/inoreader/html_clip/1006346356/News?limit=3" path="/html_clip/:user/:tag" :paramsDesc="[
'用户 id, 即举例网址 URL 中的 user/ 后的数字',
'标签名, 即举例网址 URL 中的 tag/ 后的内容'
]">
可携带 query 参数 `limit=n`, 用于限制获取的文章数量,缺省为 20
举例网址: <https://www.inoreader.com/stream/user/1006346356/tag/News/view/html?n=3>
</Route>
## kakuyomu
### 章节更新
+46
View File
@@ -0,0 +1,46 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const type = 'html';
const user = ctx.params.user;
const tag = ctx.params.tag;
const num = ctx.query.limit || 20;
const rootUrl = 'https://www.inoreader.com/stream';
const currentUrl = `${rootUrl}/user/${user}/tag/${tag}/view/${type}?n=${num}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const data = response.data;
const $ = cheerio.load(data);
const entries = $('#snip_body>.article_content');
ctx.state.data = {
title: $('.header_text').text().trim(),
link: currentUrl,
item: entries
.map((idx, item) => {
const content = $(item).clone();
const header = $(item).prev();
const pubDate = $('div.article_author .au1', header)
.contents()
.filter((_, e) => e.nodeType === 3)
.text()
.replace(/posted (on|at) /, '')
.replace(/UTC.*/, '');
return {
title: $('a.title_link', header).text().trim(),
link: $('a.title_link', header).attr('href'),
author: $('div.article_author span span', header).text().trim() + ' via ' + $('div.article_author a.feed_link', header).text().trim(),
pubDate: parseDate(pubDate, ['MMM DD YYYY HH:mm:ss', 'HH:mm:ss']),
description: $(content).html(),
};
})
.get(),
allowEmpty: true,
};
ctx.state.json = ctx.state.data;
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/html_clip/:user/:tag/:num?': ['BeautyyuYanli'],
};
+17
View File
@@ -0,0 +1,17 @@
module.exports = {
'inoreader.com': {
_name: 'Inoreader',
'.': [
{
title: 'HTML Clip',
docs: 'https://docs.rsshub.app/reading.html#inoreader',
source: ['/stream/user/:user/tag/:tag/*'],
target: (params, url) => {
const origin = new URL(url);
const limit = origin.searchParams.get('n');
return `/inoreader/html_clip/${params.user}/${params.tag}` + (limit ? `?limit=${limit}` : '');
},
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/html_clip/:user/:tag', require('./index'));
};