From ea304a361b7ee0418c02bfea88b550052de7b426 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Wed, 23 Feb 2022 00:03:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=8D=8E=E4=BA=BA?= =?UTF-8?q?=E5=A4=B4=E6=9D=A1=20(#7936)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 华人头条 * fix: add timezone * refactor: migrate to v2 Co-authored-by: TonyRL --- docs/new-media.md | 28 ++++++++++++++++++ lib/v2/52hrtt/index.js | 57 +++++++++++++++++++++++++++++++++++++ lib/v2/52hrtt/maintainer.js | 4 +++ lib/v2/52hrtt/radar.js | 19 +++++++++++++ lib/v2/52hrtt/router.js | 4 +++ lib/v2/52hrtt/symposium.js | 57 +++++++++++++++++++++++++++++++++++++ 6 files changed, 169 insertions(+) create mode 100644 lib/v2/52hrtt/index.js create mode 100644 lib/v2/52hrtt/maintainer.js create mode 100644 lib/v2/52hrtt/radar.js create mode 100644 lib/v2/52hrtt/router.js create mode 100644 lib/v2/52hrtt/symposium.js diff --git a/docs/new-media.md b/docs/new-media.md index 7f241a99d3..b8eb59c32f 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -64,6 +64,34 @@ pageClass: routes +## 52hrtt 华人头条 + +### 新闻 + + + +地区和分类皆可在浏览器地址栏中找到,下面是一个例子。 + +访问华人头条全球站的国际分类,会跳转到 。其中 `global` 即为 **全球** 对应的地区代码,`A1459145516533` 即为 **国际** 对应的分类代码。 + + + +### 专题 + + + +专题 id 和 子分类 id 皆可在浏览器地址栏中找到,下面是一个例子。 + +访问 “邱毅看平潭” 专题,会跳转到 。其中 `F1626082387819` 即为 **专题 id** 对应的地区代码。 + +::: tip 提示 + +更多的专题可以点击 [这里](https://www.52hrtt.com/global/n/w/symposium) + +::: + + + ## 9To5 ### 9To5 分站 diff --git a/lib/v2/52hrtt/index.js b/lib/v2/52hrtt/index.js new file mode 100644 index 0000000000..7eac5e4821 --- /dev/null +++ b/lib/v2/52hrtt/index.js @@ -0,0 +1,57 @@ +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 area = ctx.params.area ?? 'global'; + const type = ctx.params.type ?? ''; + + const rootUrl = 'https://www.52hrtt.com'; + const currentUrl = `${rootUrl}/${area}/n/w${type ? `?infoTypeId=${type}` : ''}`; + const apiUrl = `${rootUrl}/s/webapi/${area}/n/w${type ? `?infoTypeId=${type}` : ''}`; + + const response = await got({ + method: 'get', + url: apiUrl, + }); + + const titleResponse = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(titleResponse.data); + + const list = response.data.data.infosMap.infoList + .filter((item) => item.infoTitle) + .map((item) => ({ + title: item.infoTitle, + author: item.quoteFrom, + pubDate: timezone(parseDate(item.infoStartTime), +8), + link: `${rootUrl}/${area}/n/w/info/${item.infoCentreId}`, + })); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('.info-content').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${response.data.data.area.areaName} - ${$('.router-link-active').eq(0).text()} - 华人头条`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/52hrtt/maintainer.js b/lib/v2/52hrtt/maintainer.js new file mode 100644 index 0000000000..99757cbb46 --- /dev/null +++ b/lib/v2/52hrtt/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/symposium/:id?/:classId?': ['nczitzk'], + '/:area?/:type?': ['nczitzk'], +}; diff --git a/lib/v2/52hrtt/radar.js b/lib/v2/52hrtt/radar.js new file mode 100644 index 0000000000..9621ec17da --- /dev/null +++ b/lib/v2/52hrtt/radar.js @@ -0,0 +1,19 @@ +module.exports = { + '52hrtt.com': { + _name: '52hrtt 华人头条', + '.': [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/new-media.html#_52hrtt-hua-ren-tou-tiao', + source: '/', + target: (_params, url) => `/52hrtt/${new URL(url).searchParams.get('infoTypeId')}`, + }, + { + title: '专题', + docs: 'https://docs.rsshub.app/new-media.html#_52hrtt-hua-ren-tou-tiao', + source: '/global/n/w/symposium/:id', + target: '/52hrtt/symposium/:id', + }, + ], + }, +}; diff --git a/lib/v2/52hrtt/router.js b/lib/v2/52hrtt/router.js new file mode 100644 index 0000000000..19c281f8d8 --- /dev/null +++ b/lib/v2/52hrtt/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/symposium/:id?/:classId?', require('./symposium')); + router.get('/:area?/:type?', require('./')); +}; diff --git a/lib/v2/52hrtt/symposium.js b/lib/v2/52hrtt/symposium.js new file mode 100644 index 0000000000..1330490f67 --- /dev/null +++ b/lib/v2/52hrtt/symposium.js @@ -0,0 +1,57 @@ +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 classId = ctx.params.classId ?? ''; + + const rootUrl = 'https://www.52hrtt.com'; + const currentUrl = `${rootUrl}/global/n/w/symposium/${id}`; + const apiUrl = `${rootUrl}/s/webapi/global/symposium/getInfoList?symposiumId=${id}${classId ? `&symposiumclassId=${classId}` : ''}`; + + const response = await got({ + method: 'get', + url: apiUrl, + }); + + const titleResponse = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(titleResponse.data); + + const list = response.data.data + .filter((item) => item.infoTitle) + .map((item) => ({ + title: item.infoTitle, + author: item.quoteFrom, + pubDate: timezone(parseDate(item.infoStartTime), +8), + link: `${rootUrl}/global/n/w/info/${item.infoCentreId}`, + })); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('.info-content').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};