diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 1c138a28a..df3531a6b 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -634,6 +634,18 @@ IT・科学 tech_science +## 东网 + + + +频道参数可以从官网的地址中获取,如: + +`https://hk.on.cc/hk/finance/index_cn.html` 对应 `/oncc/zh-hans/finance` + +`https://hk.on.cc/hk/finance/index.html` 对应 `/oncc/zh-hant/finance` + + + ## 読売新聞 ### 新聞 diff --git a/lib/v2/oncc/index.js b/lib/v2/oncc/index.js new file mode 100644 index 000000000..8214931ad --- /dev/null +++ b/lib/v2/oncc/index.js @@ -0,0 +1,83 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const path = require('path'); +const { art } = require('@/utils/render'); + +const rootUrl = 'https://hk.on.cc'; + +const languageMap = { + 'zh-hans': '_cn', + 'zh-hant': '', +}; + +const channelMap = { + news: { + 'zh-hans': '港澳', + 'zh-hant': '港澳', + }, + cnnews: { + 'zh-hans': '两岸', + 'zh-hant': '兩岸', + }, + intnews: { + 'zh-hans': '国际', + 'zh-hant': '國際', + }, + commentary: { + 'zh-hans': '评论', + 'zh-hant': '評論', + }, + finance: { + 'zh-hans': '产经', + 'zh-hant': '產經', + }, +}; + +module.exports = async (ctx) => { + const language = ctx.params.language; + const channel = ctx.params.channel ?? 'news'; + const newsUrl = `${rootUrl}/hk/${channel}/index${languageMap[language]}.html`; + + const response = await got.get(newsUrl); + const $ = cheerio.load(response.data); + const list = $('#focusNews > div.focusItem[type=article]') + .map((_, item) => { + const title = $(item).find('div.focusTitle > span').text(); + const link = rootUrl + $(item).find('a:nth-child(1)').attr('href'); + const pubDate = parseDate($(item).attr('edittime'), 'YYYYMMDDHHmmss'); + + return { + title, + link, + pubDate, + }; + }) + .get(); + + const items = await Promise.all( + list.map(async (item) => { + const desc = await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got.get(item.link); + const $ = cheerio.load(detailResponse.data); + const imageUrl = rootUrl + $('img').eq(0).attr('src'); + const content = $('div.breakingNewsContent').html(); + const description = art(path.join(__dirname, 'templates/article.art'), { + imageUrl, + content, + }); + + return description; + }); + item.description = desc; + + return item; + }) + ); + + ctx.state.data = { + title: `東網 - ${channelMap[channel][language]}`, + link: newsUrl, + item: items, + }; +}; diff --git a/lib/v2/oncc/maintainer.js b/lib/v2/oncc/maintainer.js new file mode 100644 index 000000000..b278b5baa --- /dev/null +++ b/lib/v2/oncc/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:language/:channel?': ['Fatpandac'], +}; diff --git a/lib/v2/oncc/radar.js b/lib/v2/oncc/radar.js new file mode 100644 index 000000000..397dcd096 --- /dev/null +++ b/lib/v2/oncc/radar.js @@ -0,0 +1,37 @@ +module.exports = { + 'on.cc': { + _name: '东网', + hk: [ + { + title: '港澳', + docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui', + source: ['/hk/news/index.html', '/hk/news/index_cn.html'], + target: '/oncc/zh-hans/news', + }, + { + title: '两岸', + docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui', + source: ['/hk/cnnews/index.html', '/hk/cnnews/index_cn.html'], + target: '/oncc/zh-hans/cnnews', + }, + { + title: '国际', + docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui', + source: ['/hk/intnews/index.html', '/hk/intnews/index_cn.html'], + target: '/oncc/zh-hans/intnews', + }, + { + title: '评论', + docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui', + source: ['/hk/commentary/index.html', '/hk/commentary/index_cn.html'], + target: '/oncc/zh-hans/commentary', + }, + { + title: '产经', + docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui', + source: ['/hk/finance/index.html', '/hk/finance/index_cn.html'], + target: '/oncc/zh-hans/finance', + }, + ], + }, +}; diff --git a/lib/v2/oncc/router.js b/lib/v2/oncc/router.js new file mode 100644 index 000000000..ab1e01461 --- /dev/null +++ b/lib/v2/oncc/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:language/:channel?', require('./index')); +}; diff --git a/lib/v2/oncc/templates/article.art b/lib/v2/oncc/templates/article.art new file mode 100644 index 000000000..1fd784e87 --- /dev/null +++ b/lib/v2/oncc/templates/article.art @@ -0,0 +1,2 @@ + +{{ content }}