From 9e6cf26a6e14e0ca8a071d9014ed393120e2bd1f Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 17:11:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=8F=B0=E7=81=A3?= =?UTF-8?q?=E8=A1=9B=E7=94=9F=E7=A6=8F=E5=88=A9=E9=83=A8=E5=8D=B3=E6=99=82?= =?UTF-8?q?=E6=96=B0=E8=81=9E=E6=BE=84=E6=B8=85=20(#8576)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/government.md | 6 +++++ lib/v2/mohw/clarification.js | 50 ++++++++++++++++++++++++++++++++++++ lib/v2/mohw/maintainer.js | 3 +++ lib/v2/mohw/radar.js | 13 ++++++++++ lib/v2/mohw/router.js | 3 +++ 5 files changed, 75 insertions(+) create mode 100644 lib/v2/mohw/clarification.js create mode 100644 lib/v2/mohw/maintainer.js create mode 100644 lib/v2/mohw/radar.js create mode 100644 lib/v2/mohw/router.js diff --git a/docs/government.md b/docs/government.md index 7b0fdbb71..30fd1c689 100644 --- a/docs/government.md +++ b/docs/government.md @@ -234,6 +234,12 @@ pageClass: routes +## 台灣衛生福利部 + +### 即時新聞澄清 + + + ## 武汉东湖新技术开发区 ### 新闻中心 diff --git a/lib/v2/mohw/clarification.js b/lib/v2/mohw/clarification.js new file mode 100644 index 000000000..354f59bc0 --- /dev/null +++ b/lib/v2/mohw/clarification.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.mohw.gov.tw'; + const currentUrl = `${rootUrl}/lp-17-1.html`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('.list01 a[title]') + .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('article').html(); + item.pubDate = parseDate(content('meta[name="DC.Date"]').attr('datetime')); + + return item; + }) + ) + ); + + ctx.state.data = { + title: '即時新聞澄清 - 台灣衛生福利部', + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/mohw/maintainer.js b/lib/v2/mohw/maintainer.js new file mode 100644 index 000000000..724b6bb16 --- /dev/null +++ b/lib/v2/mohw/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/clarification': ['nczitzk'], +}; diff --git a/lib/v2/mohw/radar.js b/lib/v2/mohw/radar.js new file mode 100644 index 000000000..ae2f29fe3 --- /dev/null +++ b/lib/v2/mohw/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'mohw.gov.tw': { + _name: '台灣衛生福利部', + '.': [ + { + title: '即時新聞澄清', + docs: 'https://docs.rsshub.app/government.html#tai-wan-wei-sheng-fu-li-bu-ji-shi-xin-wen-cheng-qing', + source: ['/'], + target: '/mohw/clarification', + }, + ], + }, +}; diff --git a/lib/v2/mohw/router.js b/lib/v2/mohw/router.js new file mode 100644 index 000000000..da01389b2 --- /dev/null +++ b/lib/v2/mohw/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/clarification', require('./clarification')); +};