From a921d682014709458e4ca8b5ef2737b98dc6916c Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Thu, 1 Sep 2022 19:32:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E8=99=8E=E5=97=85=20?= =?UTF-8?q?=E7=AE=80=E6=8A=A5=20(#10663)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 虎嗅 简报 * Update lib/v2/huxiu/briefColumn.js Co-authored-by: Tony * fix(route): get tittle * Update lib/v2/huxiu/briefColumn.js --- docs/new-media.md | 4 +++ lib/v2/huxiu/briefColumn.js | 51 +++++++++++++++++++++++++++++++++++++ lib/v2/huxiu/radar.js | 6 +++++ lib/v2/huxiu/router.js | 1 + 4 files changed, 62 insertions(+) create mode 100644 lib/v2/huxiu/briefColumn.js diff --git a/docs/new-media.md b/docs/new-media.md index 147497676d..bf04cdd692 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2310,6 +2310,10 @@ others = 热点新闻 + 滚动新闻 +### 简报 + + + ## 互动吧 ### 活动 diff --git a/lib/v2/huxiu/briefColumn.js b/lib/v2/huxiu/briefColumn.js new file mode 100644 index 0000000000..44a6261f9f --- /dev/null +++ b/lib/v2/huxiu/briefColumn.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { id } = ctx.params; + const link = `https://api-brief.huxiu.com/briefColumn/getContentListByCategoryId`; + const response = await got + .post(link, { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: `platform=www&brief_column_id=${id}&last_id=`, + }) + .json(); + + const list = response.data.datalist; + + const items = await Promise.all( + list.map((item) => { + const link = `https://www.huxiu.com/brief/${item.brief_id}`; + + return ctx.cache.tryGet(link, async () => { + const detailResponse = await got(link); + const $ = cheerio.load(detailResponse.data); + + const description = $('#js-part').html(); + + return { + title: item.title, + pubDate: item.format_publish_time.includes('前') ? parseRelativeDate(item.format_publish_time) : parseDate(item.format_publish_time), + description, + link, + }; + }); + }) + ); + + const title = async () => { + const res = await got(`https://www.huxiu.com/briefColumn/${id}.html`); + const $ = cheerio.load(res.data); + + return $('#top > div:nth-child(1) > div > div.brief-content__name').text(); + }; + + ctx.state.data = { + title: `虎嗅 - ${await title()}`, + link: `https://www.huxiu.com/briefColumn/${id}.html`, + item: items, + }; +}; diff --git a/lib/v2/huxiu/radar.js b/lib/v2/huxiu/radar.js index 6c79dce118..f286f8f72f 100644 --- a/lib/v2/huxiu/radar.js +++ b/lib/v2/huxiu/radar.js @@ -36,6 +36,12 @@ module.exports = { source: ['/collection/:id', '/'], target: (params) => `/huxiu/collection/${params.id.replace('.html', '')}`, }, + { + title: '简报', + docs: 'https://docs.rsshub.app/new-media.html#hu-xiu', + source: ['/briefColumn/:id', '/'], + target: (params) => `/huxiu/briefcolumn/${params.id.replace('.html', '')}`, + }, ], }, }; diff --git a/lib/v2/huxiu/router.js b/lib/v2/huxiu/router.js index f1fe6db949..d527815d6f 100644 --- a/lib/v2/huxiu/router.js +++ b/lib/v2/huxiu/router.js @@ -5,4 +5,5 @@ module.exports = (router) => { router.get('/moment', require('./moment')); router.get('/tag/:id', require('./tag')); router.get('/search/:keyword', require('./search')); + router.get('/briefcolumn/:id', require('./briefColumn')); };