mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 06:30:40 +08:00
feat: add route for China Times (#3479)
This commit is contained in:
@@ -830,4 +830,16 @@
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
'chinatimes.com': {
|
||||
_name: '中時電子報',
|
||||
www: [
|
||||
{
|
||||
title: '新聞',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#zhong-shi-dian-zi-bao',
|
||||
source: '/:caty',
|
||||
target: (params) => '/chinatimes/' + params.caty,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -20,6 +20,18 @@ Support major channels, refer to [BBC RSS feeds](https://www.bbc.co.uk/news/1062
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## China Times
|
||||
|
||||
### News
|
||||
|
||||
<RouteEn author="luyuhuang" example="/chinatimes/realtimenews" path="/chinatimes/:caty" :paramsDesc="['category']" radar="1">
|
||||
|
||||
| realtimenews | politic | opinion | life | star | money | society | hottopic | tube | world | armament | chinese | fashion | sports | technologynews | travel | album |
|
||||
| -------------- | ------- | ------- | ---- | ------- | ------- | ------- | ---------- | ------ | ----- | -------- | ----------------- | ------- | ------ | --------------- | ------ | ------- |
|
||||
| Real Time News | Politic | Opinion | Life | Showbiz | Finance | Society | Hot Topics | Videos | World | Military | Mainland & Taiwan | Fashion | Sports | Technology News | Travel | Columns |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## The Guardian
|
||||
|
||||
### Editorial
|
||||
|
||||
@@ -448,3 +448,15 @@ category 对应的关键词有
|
||||
| thelatest | news_bilingual | news_hotwords | practice_tongue | trans_collect | video_links | audio_cd | columnist | 5af95d44a3103f6866ee845c | englishexams |
|
||||
|
||||
</Route>
|
||||
|
||||
## 中時電子報
|
||||
|
||||
### 新聞
|
||||
|
||||
<Route author="luyuhuang" example="/chinatimes/realtimenews" path="/chinatimes/:caty" :paramsDesc="['类别']" radar="1">
|
||||
|
||||
| realtimenews | politic | opinion | life | star | money | society | hottopic | tube | world | armament | chinese | fashion | sports | technologynews | travel | album |
|
||||
| ------------ | ------- | ------- | ---- | ---- | ----- | ------- | -------- | ------- | ----- | -------- | ------- | ------- | ------ | -------------- | ------ | ----- |
|
||||
| 即時 | 政治 | 言論 | 生活 | 娛樂 | 財經 | 社會 | 話題 | 快點 TV | 國際 | 軍事 | 兩岸 | 時尚 | 體育 | 科技 | 玩食 | 專輯 |
|
||||
|
||||
</Route>
|
||||
|
||||
@@ -1995,6 +1995,9 @@ router.get('/itslide/new', require('./routes/itslide/new'));
|
||||
// Remote Work
|
||||
router.get('/remote-work/:caty?', require('./routes/remote-work/index'));
|
||||
|
||||
// China Times
|
||||
router.get('/chinatimes/:caty', require('./routes/chinatimes/index'));
|
||||
|
||||
// TransferWise
|
||||
router.get('/transferwise/pair/:source/:target', require('./routes/transferwise/pair'));
|
||||
|
||||
|
||||
115
lib/routes/chinatimes/index.js
Normal file
115
lib/routes/chinatimes/index.js
Normal file
@@ -0,0 +1,115 @@
|
||||
const url = require('url');
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const root_url = 'https://www.chinatimes.com';
|
||||
|
||||
const config = {
|
||||
realtimenews: {
|
||||
link: '/realtimenews/?chdtv',
|
||||
title: 'China Times - Real Time News',
|
||||
},
|
||||
politic: {
|
||||
link: '/politic/?chdtv',
|
||||
title: 'China Times - Politic',
|
||||
},
|
||||
opinion: {
|
||||
link: '/opinion/?chdtv',
|
||||
title: 'China Times - Opinion',
|
||||
},
|
||||
life: {
|
||||
link: '/life/?chdtv',
|
||||
title: 'China Times - Life',
|
||||
},
|
||||
star: {
|
||||
link: '/star/?chdtv',
|
||||
title: 'China Times - Showbiz',
|
||||
},
|
||||
money: {
|
||||
link: '/money/?chdtv',
|
||||
title: 'China Times - Finance',
|
||||
},
|
||||
society: {
|
||||
link: '/society/?chdtv',
|
||||
title: 'China Times - Society',
|
||||
},
|
||||
hottopic: {
|
||||
link: '/hottopic/?chdtv',
|
||||
title: 'China Times - Hot Topics',
|
||||
},
|
||||
tube: {
|
||||
link: '/tube/?chdtv',
|
||||
title: 'China Times - Videos',
|
||||
},
|
||||
world: {
|
||||
link: '/world/?chdtv',
|
||||
title: 'China Times - World',
|
||||
},
|
||||
armament: {
|
||||
link: '/armament/?chdtv',
|
||||
title: 'China Times - Military',
|
||||
},
|
||||
chinese: {
|
||||
link: '/chinese/?chdtv',
|
||||
title: 'China Times - Mainland & Taiwan',
|
||||
},
|
||||
fashion: {
|
||||
link: '/fashion/?chdtv',
|
||||
title: 'China Times - Fashion',
|
||||
},
|
||||
sports: {
|
||||
link: '/sports/?chdtv',
|
||||
title: 'China Times - Sports',
|
||||
},
|
||||
technologynews: {
|
||||
link: '/technologynews/?chdtv',
|
||||
title: 'China Times - Technology News',
|
||||
},
|
||||
travel: {
|
||||
link: '/travel/?chdtv',
|
||||
title: 'China Times - Travel',
|
||||
},
|
||||
album: {
|
||||
link: '/album/?chdtv',
|
||||
title: 'China Times - Columns',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const cfg = config[ctx.params.caty];
|
||||
if (!cfg) {
|
||||
throw Error('Bad category. See <a href="https://docs.rsshub.app/traditional-media.html#zhong-shi-dian-zi-bao">https://docs.rsshub.app/traditional-media.html#zhong-shi-dian-zi-bao</a>');
|
||||
}
|
||||
|
||||
const current_url = url.resolve(root_url, cfg.link);
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: current_url,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('section.article-list ul div.row')
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const right = item.find('div.col');
|
||||
const a = right.find('h3.title a');
|
||||
const img = item.find('img.photo').attr('src');
|
||||
let desc = '<p>' + right.find('p.intro').text() + '...</p>';
|
||||
if (img) {
|
||||
desc = `<p><img src="${img}"></p>` + desc;
|
||||
}
|
||||
return {
|
||||
title: a.text(),
|
||||
link: a.attr('href'),
|
||||
pubDate: new Date(right.find('div.meta-info time').attr('datetime') + ' GMT+8').toUTCString(),
|
||||
description: desc,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
ctx.state.data = {
|
||||
title: cfg.title,
|
||||
link: current_url,
|
||||
item: list,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user