From cb7a9fa5a79bded0291111a3a33892ef0bccd7fe Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Fri, 11 Aug 2023 03:17:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=97=A9=E6=8A=A5?= =?UTF-8?q?=E7=BD=91=20(#12981)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 12 ++++++ lib/v2/qqorw/index.js | 77 ++++++++++++++++++++++++++++++++++++++ lib/v2/qqorw/maintainer.js | 4 ++ lib/v2/qqorw/radar.js | 13 +++++++ lib/v2/qqorw/router.js | 3 ++ 5 files changed, 109 insertions(+) create mode 100644 lib/v2/qqorw/index.js create mode 100644 lib/v2/qqorw/maintainer.js create mode 100644 lib/v2/qqorw/radar.js create mode 100644 lib/v2/qqorw/router.js diff --git a/docs/new-media.md b/docs/new-media.md index e7f646ab2..1188d8ca0 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -4862,6 +4862,18 @@ column 为 third 时可选的 category: +## 早报网 + +### 每日早报 + + + +| 首页 | 每日早报 | 国际早报 | 生活冷知识 | +| ---- | -------- | -------- | ---------- | +| | mrzb | zbapp | zbzzd | + + + ## 知园 ### Newsletter diff --git a/lib/v2/qqorw/index.js b/lib/v2/qqorw/index.js new file mode 100644 index 000000000..2f51f2763 --- /dev/null +++ b/lib/v2/qqorw/index.js @@ -0,0 +1,77 @@ +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 { category = '' } = ctx.params; + const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 10; + + const rootUrl = 'https://qqorw.cn'; + const currentUrl = new URL(category, rootUrl).href; + + const { data: response } = await got(currentUrl); + + const $ = cheerio.load(response); + + let items = $('article.excerpt') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + const a = item.find('h2 a'); + + return { + title: a.text(), + link: a.prop('href'), + description: item.find('span.note').text(), + category: item + .find('a.label') + .toArray() + .map((c) => $(c).text()), + pubDate: timezone(parseDate(item.find('p.auth-span span.muted').first().text().trim()), +8), + upvotes: item.find('span.count').text() ? parseInt(item.find('span.count').text(), 10) : 0, + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: detailResponse } = await got(item.link); + + const content = cheerio.load(detailResponse); + + content('div.contenttxt').prev().nextAll().remove(); + + item.title = content('h1.article-title').text(); + item.description = content('article.article-content').html(); + item.author = content('i.fa-user').parent().text().trim(); + item.category = content('#mute-category') + .toArray() + .map((c) => content(c).text().trim()); + item.pubDate = item.pubDate ?? parseDate(content('i.fa-clock-o').parent().text().trim()); + item.upvotes = content('#Addlike span.count').text() ? parseInt(content('#Addlike span.count').text(), 10) : item.upvotes; + + return item; + }) + ) + ); + + const author = '早报网'; + const icon = new URL('favicon.ico', rootUrl).href; + const title = $('header.archive-header h1 a').last().text(); + + ctx.state.data = { + item: items, + title: `${author}${title ? ` - ${title}` : ''}`, + link: currentUrl, + description: $('meta[name="description"]').prop('content'), + language: 'zh-cn', + image: new URL($('h1.site-title a img').prop('src'), rootUrl).href, + icon, + logo: icon, + subtitle: $('meta[name="keywords"]').prop('content'), + author, + }; +}; diff --git a/lib/v2/qqorw/maintainer.js b/lib/v2/qqorw/maintainer.js new file mode 100644 index 000000000..ee544d6c9 --- /dev/null +++ b/lib/v2/qqorw/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/:category?': ['nczitzk'], + '': ['nczitzk'], +}; diff --git a/lib/v2/qqorw/radar.js b/lib/v2/qqorw/radar.js new file mode 100644 index 000000000..84627068d --- /dev/null +++ b/lib/v2/qqorw/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'qqorw.cn': { + _name: '早报网', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/new-media.html#zao-bao-wang-fen-lei', + source: ['/:category', '/'], + target: '/qqorw/:category?', + }, + ], + }, +}; diff --git a/lib/v2/qqorw/router.js b/lib/v2/qqorw/router.js new file mode 100644 index 000000000..2b42dc32a --- /dev/null +++ b/lib/v2/qqorw/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category?', require('./')); +};