From 8b82fd0f86dab1a15b4f8e4fda072288cddab698 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 16:57:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=85=A8=E6=B0=91?= =?UTF-8?q?=E5=81=A5=E5=BA=B7=E7=BD=91=20(#8507)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 18 ++++++++++++++ lib/v2/qm120/maintainer.js | 3 +++ lib/v2/qm120/news.js | 50 ++++++++++++++++++++++++++++++++++++++ lib/v2/qm120/radar.js | 13 ++++++++++ lib/v2/qm120/router.js | 3 +++ 5 files changed, 87 insertions(+) create mode 100644 lib/v2/qm120/maintainer.js create mode 100644 lib/v2/qm120/news.js create mode 100644 lib/v2/qm120/radar.js create mode 100644 lib/v2/qm120/router.js diff --git a/docs/new-media.md b/docs/new-media.md index 8775a7fb5..7c4c9da12 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2243,6 +2243,24 @@ column 为 third 时可选的 category: +## 全民健康网 + + + +| 健康焦点 | 行业动态 | 医学前沿 | 法规动态 | +| -------- | -------- | -------- | -------- | +| jdxw | hydt | yxqy | fgdt | + +| 食品安全 | 医疗事故 | 医药会展 | 医药信息 | +| -------- | -------- | -------- | -------- | +| spaq | ylsg | yyhz | yyxx | + +| 新闻专题 | 行业新闻 | +| -------- | -------- | +| zhuanti | xyxw | + + + ## 全球化智库 ### 分类 diff --git a/lib/v2/qm120/maintainer.js b/lib/v2/qm120/maintainer.js new file mode 100644 index 000000000..d4350891f --- /dev/null +++ b/lib/v2/qm120/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news/:category?': ['nczitzk'], +}; diff --git a/lib/v2/qm120/news.js b/lib/v2/qm120/news.js new file mode 100644 index 000000000..492d8b06c --- /dev/null +++ b/lib/v2/qm120/news.js @@ -0,0 +1,50 @@ +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.category ?? 'jdxw'; + + const rootUrl = 'http://www.qm120.com'; + const currentUrl = `${rootUrl}/news/${category}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('.lb2boxls ul li a') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.text(), + link: item.attr('href'), + }; + }); + + items = await Promise.all( + items.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('.neirong_body').html(); + item.pubDate = timezone(parseDate(content('.neirong_head p span').eq(1).text()), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('.zt_liebiao_tit').text()} - 全民健康网`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/qm120/radar.js b/lib/v2/qm120/radar.js new file mode 100644 index 000000000..3dab14b0e --- /dev/null +++ b/lib/v2/qm120/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'qm120.com': { + _name: '全民健康网', + '.': [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/new-media.html#quan-min-jian-kang-wang-xin-wen', + source: ['/'], + target: '/qm120/news/:category?', + }, + ], + }, +}; diff --git a/lib/v2/qm120/router.js b/lib/v2/qm120/router.js new file mode 100644 index 000000000..dae94fc37 --- /dev/null +++ b/lib/v2/qm120/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/news/:category?', require('./news')); +};