From 3b41c3d1f0c62c376705ad0566046b2787a42c6e Mon Sep 17 00:00:00 2001 From: nczitzk Date: Mon, 18 Oct 2021 07:33:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20HKJunkCall=E8=B3=87?= =?UTF-8?q?=E8=A8=8A=E4=B8=AD=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 6 ++++ lib/v2/hkjunkcall/index.js | 53 +++++++++++++++++++++++++++++++++ lib/v2/hkjunkcall/maintainer.js | 3 ++ lib/v2/hkjunkcall/radar.js | 13 ++++++++ lib/v2/hkjunkcall/router.js | 3 ++ 5 files changed, 78 insertions(+) create mode 100644 lib/v2/hkjunkcall/index.js create mode 100644 lib/v2/hkjunkcall/maintainer.js create mode 100644 lib/v2/hkjunkcall/radar.js create mode 100644 lib/v2/hkjunkcall/router.js diff --git a/docs/new-media.md b/docs/new-media.md index cebd7eaa88b9ef..c2bd61cd306d44 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -364,6 +364,12 @@ Tag +## HKJunkCall 資訊中心 + +### 近期資訊 + + + ## iDaily 每日环球视野 ### 今日 Timeline diff --git a/lib/v2/hkjunkcall/index.js b/lib/v2/hkjunkcall/index.js new file mode 100644 index 00000000000000..c0a57d13a8c5f2 --- /dev/null +++ b/lib/v2/hkjunkcall/index.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://hkjunkcall.com'; + const currentUrl = `${rootUrl}/cdpushdash.asp`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.hh15') + .map((_, item) => { + item = $(item).parent(); + + return { + title: item.text(), + link: item.attr('href'), + }; + }) + .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); + + content('.card').find('div, h2').remove(); + + item.guid = item.link.split('/').pop(); + item.description = content('.card').html(); + item.pubDate = parseDate(detailResponse.data.match(/
(\d+-\d+-\d+)<\/div><\/a>/)[1]); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/hkjunkcall/maintainer.js b/lib/v2/hkjunkcall/maintainer.js new file mode 100644 index 00000000000000..ca7cf1eb13c68a --- /dev/null +++ b/lib/v2/hkjunkcall/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/': ['nczitzk'], +}; diff --git a/lib/v2/hkjunkcall/radar.js b/lib/v2/hkjunkcall/radar.js new file mode 100644 index 00000000000000..284fbb66abf9b2 --- /dev/null +++ b/lib/v2/hkjunkcall/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'hkjunkcall.com': { + _name: 'HKJunkCall資訊中心', + '.': [ + { + title: '近期資訊', + docs: 'https://docs.rsshub.app/new-media.html#hkjunkcall-zi-xun-zhong-xin-jin-qi-zi-xun', + source: ['/'], + target: '/hkjunkcall', + }, + ], + }, +}; diff --git a/lib/v2/hkjunkcall/router.js b/lib/v2/hkjunkcall/router.js new file mode 100644 index 00000000000000..20c52b09d72938 --- /dev/null +++ b/lib/v2/hkjunkcall/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/', require('./index')); +};