Add(route): add 东网 (#8785)
This commit is contained in:
parent
b5be05b1e2
commit
b8acfdbf7b
|
|
@ -634,6 +634,18 @@ IT・科学 tech_science
|
|||
|
||||
<Route author="nczitzk" example="/eastday/portrait" path="/eastday/portrait"/>
|
||||
|
||||
## 东网
|
||||
|
||||
<Route author="Fatpandac" example="/oncc/zh-hant/news" path="/oncc/:language/:channel?" :paramsDesc="['`zh-hans` 为简体,`zh-hant` 为繁体', '频道,默认为港澳']">
|
||||
|
||||
频道参数可以从官网的地址中获取,如:
|
||||
|
||||
`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`
|
||||
|
||||
</Route>
|
||||
|
||||
## 読売新聞
|
||||
|
||||
### 新聞
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/:language/:channel?': ['Fatpandac'],
|
||||
};
|
||||
|
|
@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/:language/:channel?', require('./index'));
|
||||
};
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
<img src="{{ imageUrl }}">
|
||||
{{ content }}
|
||||
Loading…
Reference in New Issue