feat(route): add mingpao (#8255)
Co-authored-by: SettingDust <settingdust@gmail.com>
This commit is contained in:
parent
f9e5212392
commit
5f0167643d
|
|
@ -175,6 +175,32 @@ Generates full-text feeds that the official feed doesn't provide.
|
|||
|
||||
</RouteEn>
|
||||
|
||||
## Ming Pao
|
||||
|
||||
### Ming Pao Daily
|
||||
|
||||
<RouteEn author="TonyRL" example="/mingpao/pns/s00017" path="/mingpao/pns/:category?" :paramsDesc="['channel,default to brief']"/>
|
||||
|
||||
::: 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
|
||||
|
|
|
|||
|
|
@ -929,6 +929,45 @@ category 对应的关键词有
|
|||
|
||||
</Route>
|
||||
|
||||
## 明报
|
||||
|
||||
### 即时新闻
|
||||
|
||||
<Route author="TonyRL" example="/mingpao/ins/all" path="/mingpao/ins/:category?" :paramsDesc="['频道,预设为总目录']"/>
|
||||
|
||||
| category | 即时新闻频道 |
|
||||
| -------- | ------------ |
|
||||
| all | 总目录 |
|
||||
| s00001 | 港闻 |
|
||||
| s00002 | 经济 |
|
||||
| s00003 | 地产 |
|
||||
| s00004 | 两岸 |
|
||||
| s00005 | 国际 |
|
||||
| s00006 | 体育 |
|
||||
| s00007 | 娱乐 |
|
||||
| s00022 | 文摘 |
|
||||
| s00024 | 热点 |
|
||||
|
||||
### 每日明报
|
||||
|
||||
<Route author="TonyRL" example="/mingpao/pns/s00001" path="/mingpao/pns/:category?" :paramsDesc="['频道,预设为要闻']"/>
|
||||
|
||||
| category | 每日明报频道 |
|
||||
| -------- | ------------ |
|
||||
| s00001 | 要闻 |
|
||||
| s00002 | 港闻 |
|
||||
| s00003 | 社评 |
|
||||
| s00004 | 经济 |
|
||||
| s00005 | 副刊 |
|
||||
| s00011 | 教育 |
|
||||
| s00012 | 观点 |
|
||||
| s00013 | 中国 |
|
||||
| s00014 | 国际 |
|
||||
| s00015 | 体育 |
|
||||
| s00016 | 娱乐 |
|
||||
| s00017 | 英文 |
|
||||
| s00018 | 作家专栏 |
|
||||
|
||||
## 南方周末
|
||||
|
||||
### 新闻分类
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/:type?/:category?': ['TonyRL'],
|
||||
};
|
||||
|
|
@ -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?',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/:type?/:category?', require('./index'));
|
||||
};
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
{{@ pics }}
|
||||
{{@ desc }}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
{{ each pics }}
|
||||
<figure><img src="{{ $value.href }}" alt="{{ $value.title }}"><figcaption>{{ $value.title }}</figcaption></figure>
|
||||
{{ /each }}
|
||||
Loading…
Reference in New Issue