From 4f1cdf6a844c2e81a3e621844ae86c0b89cb6213 Mon Sep 17 00:00:00 2001 From: BeautyyuYanli Date: Mon, 20 Feb 2023 20:56:37 +0800 Subject: [PATCH] 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 * add pubDate * Update lib/v2/inoreader/index.js Co-authored-by: Tony --------- --- docs/en/reading.md | 16 ++++++++++++ docs/reading.md | 15 +++++++++++ lib/v2/inoreader/index.js | 46 ++++++++++++++++++++++++++++++++++ lib/v2/inoreader/maintainer.js | 3 +++ lib/v2/inoreader/radar.js | 17 +++++++++++++ lib/v2/inoreader/router.js | 3 +++ 6 files changed, 100 insertions(+) create mode 100644 lib/v2/inoreader/index.js create mode 100644 lib/v2/inoreader/maintainer.js create mode 100644 lib/v2/inoreader/radar.js create mode 100644 lib/v2/inoreader/router.js diff --git a/docs/en/reading.md b/docs/en/reading.md index 8db8c8582..09d5207cb 100644 --- a/docs/en/reading.md +++ b/docs/en/reading.md @@ -20,6 +20,22 @@ Eg: +## Inoreader + +### HTML Clip + + + +Use query parameter `limit=n` to limit the number of articles, default to 20 + +Eg: + + + + ## kakuyomu ### episode diff --git a/docs/reading.md b/docs/reading.md index 12a86ca37..22facade0 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -20,6 +20,21 @@ pageClass: routes +## Inoreader + +### HTML Clip + + + +可携带 query 参数 `limit=n`, 用于限制获取的文章数量,缺省为 20 + +举例网址: + + + ## kakuyomu ### 章节更新 diff --git a/lib/v2/inoreader/index.js b/lib/v2/inoreader/index.js new file mode 100644 index 000000000..563ff6197 --- /dev/null +++ b/lib/v2/inoreader/index.js @@ -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; +}; diff --git a/lib/v2/inoreader/maintainer.js b/lib/v2/inoreader/maintainer.js new file mode 100644 index 000000000..3860a6299 --- /dev/null +++ b/lib/v2/inoreader/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/html_clip/:user/:tag/:num?': ['BeautyyuYanli'], +}; diff --git a/lib/v2/inoreader/radar.js b/lib/v2/inoreader/radar.js new file mode 100644 index 000000000..319625db5 --- /dev/null +++ b/lib/v2/inoreader/radar.js @@ -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}` : ''); + }, + }, + ], + }, +}; diff --git a/lib/v2/inoreader/router.js b/lib/v2/inoreader/router.js new file mode 100644 index 000000000..d8961e1bb --- /dev/null +++ b/lib/v2/inoreader/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/html_clip/:user/:tag', require('./index')); +};