diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index 52c5402ac..2ead21d00 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -175,6 +175,32 @@ Generates full-text feeds that the official feed doesn't provide. +## Ming Pao + +### Ming Pao Daily + + + +::: tip tips +Only `s00017` is in English. +::: + +| category | Channel | +| -------- | ------------- | +| s00001 | Brief | +| s00002 | Local | +| s00003 | Editorial | +| s00004 | Economy | +| s00005 | Supplement | +| s00011 | Education | +| s00012 | Views | +| s00013 | China | +| s00014 | International | +| s00015 | Sports | +| s00016 | Entertainment | +| s00017 | English | +| s00018 | Columnist | + ## NHK ### News Web Easy diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 4bf9de618..c25f3f79e 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -929,6 +929,45 @@ category 对应的关键词有 +## 明报 + +### 即时新闻 + + + +| category | 即时新闻频道 | +| -------- | ------------ | +| all | 总目录 | +| s00001 | 港闻 | +| s00002 | 经济 | +| s00003 | 地产 | +| s00004 | 两岸 | +| s00005 | 国际 | +| s00006 | 体育 | +| s00007 | 娱乐 | +| s00022 | 文摘 | +| s00024 | 热点 | + +### 每日明报 + + + +| category | 每日明报频道 | +| -------- | ------------ | +| s00001 | 要闻 | +| s00002 | 港闻 | +| s00003 | 社评 | +| s00004 | 经济 | +| s00005 | 副刊 | +| s00011 | 教育 | +| s00012 | 观点 | +| s00013 | 中国 | +| s00014 | 国际 | +| s00015 | 体育 | +| s00016 | 娱乐 | +| s00017 | 英文 | +| s00018 | 作家专栏 | + ## 南方周末 ### 新闻分类 diff --git a/lib/v2/mingpao/index.js b/lib/v2/mingpao/index.js new file mode 100644 index 000000000..133b66623 --- /dev/null +++ b/lib/v2/mingpao/index.js @@ -0,0 +1,94 @@ +const got = require('@/utils/got'); +const parser = require('@/utils/rss-parser'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const type = ctx.params.type ?? 'ins'; + const category = ctx.params.category ?? (type === 'ins' ? 'all' : 's00001'); + const link = `https://news.mingpao.com/rss/${type}/${category}.xml`; + + const feed = await parser.parseURL(link); + + const renderFanBox = (pics) => + art(path.join(__dirname, 'templates/fancybox.art'), { + pics, + }); + + const renderDesc = (pics, desc) => + art(path.join(__dirname, 'templates/description.art'), { + pics: renderFanBox(pics), + desc, + }); + + const items = await Promise.all( + feed.items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const response = await got({ + method: 'get', + url: item.link, + headers: { + Referer: 'https://news.mingpao.com/', + }, + }); + + const $ = cheerio.load(response.data); + const fancyboxImg = $('a.fancybox').length ? $('a.fancybox') : $('a.fancybox-buttons'); + + // remove unwanted elements + $('div.ad300ins_m').remove(); + $('div.clear, div.inReadLrecGroup, div.clr').remove(); + $('div#ssm2').remove(); + $('iframe').remove(); + $('p[dir=ltr]').remove(); + + // extract categories + item.category = item.categories; + + // fix fancybox image + const fancybox = fancyboxImg + .map((_, e) => { + e = $(e); + return { + href: e.attr('href'), + title: e.attr('title'), + }; + }) + .get(); + + // remove unwanted key value + delete item.categories; + delete item.content; + delete item.contentSnippet; + delete item.creator; + delete item.isoDate; + + item.description = renderDesc(fancybox, $('.txt4').html() ?? $('div.article_content.line_1_5em').html()); + item.pubDate = parseDate(item.pubDate); + item.guid = item.link.indexOf('?') > 0 ? item.link : item.link.substring(0, item.link.lastIndexOf('/')); + + return item; + }) + ) + ); + + ctx.state.data = { + title: feed.title, + link: feed.link, + description: feed.description, + item: items, + image: feed.image.url, + language: feed.language, + }; + + ctx.state.json = { + title: feed.title, + link: feed.link, + description: feed.description, + item: items, + image: feed.image.url, + language: feed.language, + }; +}; diff --git a/lib/v2/mingpao/maintainer.js b/lib/v2/mingpao/maintainer.js new file mode 100644 index 000000000..d07d59caf --- /dev/null +++ b/lib/v2/mingpao/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:type?/:category?': ['TonyRL'], +}; diff --git a/lib/v2/mingpao/radar.js b/lib/v2/mingpao/radar.js new file mode 100644 index 000000000..a16bd5b12 --- /dev/null +++ b/lib/v2/mingpao/radar.js @@ -0,0 +1,36 @@ +module.exports = { + 'mingpao.com': { + _name: '明报', + '.': [ + { + title: '即时新闻', + docs: 'https://docs.rsshub.app/traditional-media.html#ming-bao', + source: ['/'], + target: '/mingpao/ins/:type?', + }, + { + title: '每日明报', + docs: 'https://docs.rsshub.app/traditional-media.html#ming-bao', + source: ['/'], + target: '/mingpao/pns/:type?', + }, + ], + }, + 'mpfinance.com': { + _name: '明报', + '.': [ + { + title: '即时新闻', + docs: 'https://docs.rsshub.app/traditional-media.html#ming-bao', + source: ['/'], + target: '/mingpao/ins/:type?', + }, + { + title: '每日明报', + docs: 'https://docs.rsshub.app/traditional-media.html#ming-bao', + source: ['/'], + target: '/mingpao/pns/:type?', + }, + ], + }, +}; diff --git a/lib/v2/mingpao/router.js b/lib/v2/mingpao/router.js new file mode 100644 index 000000000..f6aadf778 --- /dev/null +++ b/lib/v2/mingpao/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:type?/:category?', require('./index')); +}; diff --git a/lib/v2/mingpao/templates/description.art b/lib/v2/mingpao/templates/description.art new file mode 100644 index 000000000..7a0e7673e --- /dev/null +++ b/lib/v2/mingpao/templates/description.art @@ -0,0 +1,2 @@ +{{@ pics }} +{{@ desc }} diff --git a/lib/v2/mingpao/templates/fancybox.art b/lib/v2/mingpao/templates/fancybox.art new file mode 100644 index 000000000..3be1bf3dd --- /dev/null +++ b/lib/v2/mingpao/templates/fancybox.art @@ -0,0 +1,3 @@ +{{ each pics }} +
{{ $value.title }}
{{ $value.title }}
+{{ /each }}