From 5c4c688836664f6716a7b1aa2adc55949608db64 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 8 Jul 2022 16:01:59 +0500 Subject: [PATCH] feat(route): taiwannews (#10178) --- docs/en/government.md | 2 +- docs/en/traditional-media.md | 12 ++++---- docs/traditional-media.md | 6 ++++ lib/v2/taiwannews/hot.js | 52 +++++++++++++++++++++++++++++++++ lib/v2/taiwannews/maintainer.js | 3 ++ lib/v2/taiwannews/radar.js | 13 +++++++++ lib/v2/taiwannews/router.js | 3 ++ 7 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 lib/v2/taiwannews/hot.js create mode 100644 lib/v2/taiwannews/maintainer.js create mode 100644 lib/v2/taiwannews/radar.js create mode 100644 lib/v2/taiwannews/router.js diff --git a/docs/en/government.md b/docs/en/government.md index f8022ac94a..5b81107160 100644 --- a/docs/en/government.md +++ b/docs/en/government.md @@ -8,7 +8,7 @@ pageClass: routes ### Immigration and Citizenship - News - + ## Central Intelligence Agency diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index 81d29b4cfd..4e0e79a00d 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -462,6 +462,12 @@ Language +## Taiwan News + +### Hot News + + + ## The Economist ### Category @@ -589,9 +595,3 @@ Free articles only. |  news   | national | politics | economy | sports | world | science | election | culture | igoshougi | life | local | editorial | koushitsu | - -## 公視新聞網 - -### Daily News - - diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 559f0e7f81..195a9a9282 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1552,6 +1552,12 @@ category 对应的关键词有 +## 台灣英文新聞 + +### 最新熱門消息 + + + ## 卫报 The Guardian 通过提取文章全文,以提供比官方源更佳的阅读体验。 diff --git a/lib/v2/taiwannews/hot.js b/lib/v2/taiwannews/hot.js new file mode 100644 index 0000000000..23b78ef3d8 --- /dev/null +++ b/lib/v2/taiwannews/hot.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const baseUrl = 'https://www.taiwannews.com.tw'; + +module.exports = async (ctx) => { + const { lang = 'en' } = ctx.params; + const url = `${baseUrl}/${lang}/index`; + const response = await got(url); + const $ = cheerio.load(response.data); + + const list = $('.mod_group-columns .container-fluid .row') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('a'); + return { + title: a.attr('title'), + link: new URL(a.attr('href'), baseUrl).href, + pubDate: timezone(parseDate(item.find('.entry-date span').eq(1).text(), 'YYYY/MM/DD HH:mm'), +8), + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const response = await got(item.link); + const $ = cheerio.load(response.data); + + item.author = $('.article-author').text(); + item.category = $('.tagcloud a') + .toArray() + .map((a) => $(a).attr('title')); + + $('.article-head-wrapper, div[id^=div-gpt-ad-], div[class^=hidden-], footer').remove(); + $('.container-fluid').eq(2).remove(); + + item.description = $('.mod_single-column').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('.categories').eq(0).text()} - ${$('head title').text()}`, + description: $('meta[name="description"]').attr('content'), + link: url, + item: items, + language: lang, + }; +}; diff --git a/lib/v2/taiwannews/maintainer.js b/lib/v2/taiwannews/maintainer.js new file mode 100644 index 0000000000..b1ee634e01 --- /dev/null +++ b/lib/v2/taiwannews/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/hot/:lang?': ['TonyRL'], +}; diff --git a/lib/v2/taiwannews/radar.js b/lib/v2/taiwannews/radar.js new file mode 100644 index 0000000000..960b2be7e1 --- /dev/null +++ b/lib/v2/taiwannews/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'taiwannews.com.tw': { + _name: '台灣英文新聞', + '.': [ + { + title: '最新熱門消息', + docs: 'httsp://docs.rsshub.app/traditional-media.html#tai-wan-ying-wen-xin-wen', + source: '/:lang/index', + target: '/taiwannews/hot/:lang', + }, + ], + }, +}; diff --git a/lib/v2/taiwannews/router.js b/lib/v2/taiwannews/router.js new file mode 100644 index 0000000000..17d5e886fa --- /dev/null +++ b/lib/v2/taiwannews/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/hot/:lang?', require('./hot')); +};