From 3715f2b35ee67ea2651901520ab4c9d4ed1c1921 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 16:02:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E8=BE=9B=E8=8F=AF?= =?UTF-8?q?=E7=A4=BE=20(#8357)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 26 +++++++++++++++++ lib/v2/hotchina/index.js | 55 +++++++++++++++++++++++++++++++++++ lib/v2/hotchina/maintainer.js | 5 ++++ lib/v2/hotchina/radar.js | 25 ++++++++++++++++ lib/v2/hotchina/router.js | 3 ++ 5 files changed, 114 insertions(+) create mode 100644 lib/v2/hotchina/index.js create mode 100644 lib/v2/hotchina/maintainer.js create mode 100644 lib/v2/hotchina/radar.js create mode 100644 lib/v2/hotchina/router.js diff --git a/docs/new-media.md b/docs/new-media.md index f41bb6c23..65baa7c35 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2800,6 +2800,32 @@ column 为 third 时可选的 category: +## 辛華社 + +### 首页 + + + +### 分类 + + + +| 攝徒日記 | 辛華社特約報導 | 小粉紅觀察 | 維權消息 | 讀者投書 | 中國牆內 | 台灣國 | 國際 | +| -------- | -------------- | ---------- | -------- | -------- | -------- | ------ | ---- | + + + +### 标签 + + + +以下为 Top Tags: + +| 辱華 | 小粉紅 | 中國限電 | 徵稿 | 特約報導 | 舔共藝人 | 中共國慶 | +| ---- | ------ | -------- | ---- | -------- | -------- | -------- | + + + ## 新浪专栏 ### 创事记 diff --git a/lib/v2/hotchina/index.js b/lib/v2/hotchina/index.js new file mode 100644 index 000000000..05c16c919 --- /dev/null +++ b/lib/v2/hotchina/index.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const category = ctx.params.category ?? ''; + const id = ctx.params.id ?? ''; + + const rootUrl = 'https://hotchina.news'; + const currentUrl = `${rootUrl}${category && id ? `/archives/${category}/${id}` : ''}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.title') + .map((_, item) => { + item = $(item); + + const a = item.find('a'); + + return { + title: a.text(), + link: a.attr('href'), + pubDate: parseDate(item.next().find('.mg-blog-date').text().trim(), 'M 月 D, YYYY'), + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.description = content('div[itemprop="articleBody"]').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/hotchina/maintainer.js b/lib/v2/hotchina/maintainer.js new file mode 100644 index 000000000..b59adad7f --- /dev/null +++ b/lib/v2/hotchina/maintainer.js @@ -0,0 +1,5 @@ +module.exports = { + '/': ['nczitzk'], + '/category/:id?': ['nczitzk'], + '/tag/:id?': ['nczitzk'], +}; diff --git a/lib/v2/hotchina/radar.js b/lib/v2/hotchina/radar.js new file mode 100644 index 000000000..5b7482423 --- /dev/null +++ b/lib/v2/hotchina/radar.js @@ -0,0 +1,25 @@ +module.exports = { + 'hotchina.news': { + _name: '辛華社', + '.': [ + { + title: '首页', + docs: 'https://docs.rsshub.app/new-media.html#xin-hua-she-shou-ye', + source: ['/'], + target: '/hotchina', + }, + { + title: '分类', + docs: 'https://docs.rsshub.app/new-media.html#xin-hua-she-fen-lei', + source: ['/archives/category/:id', '/'], + target: '/hotchina/category/:id?', + }, + { + title: '标签', + docs: 'https://docs.rsshub.app/new-media.html#xin-hua-she-biao-qian', + source: ['/archives/tag/:id', '/'], + target: '/hotchina/tag/:id?', + }, + ], + }, +}; diff --git a/lib/v2/hotchina/router.js b/lib/v2/hotchina/router.js new file mode 100644 index 000000000..3ceee154c --- /dev/null +++ b/lib/v2/hotchina/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category?/:id?', require('./index')); +};