Skip to content

Commit

Permalink
fix(route): add Spotlight News into CNA list. (#13160)
Browse files Browse the repository at this point in the history
* fix(route): add `Spotlight News` into CNA list.

* refactor: migrate to v2

---------
  • Loading branch information
dzx-dzx authored Aug 30, 2023
1 parent 05bb835 commit 64839f0
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,7 @@ router.get('/anki/changes', lazyloadRouteHandler('./routes/anki/changes'));
router.get('/abc/:id?', lazyloadRouteHandler('./routes/abc'));

// 台湾中央通讯社
router.get('/cna/:id?', lazyloadRouteHandler('./routes/cna/index'));
// router.get('/cna/:id?', lazyloadRouteHandler('./routes/cna/index'));

// 华为心声社区
router.get('/huawei/xinsheng/:caty?/:order?/:keyword?', lazyloadRouteHandler('./routes/huawei/xinsheng/index'));
Expand Down
22 changes: 12 additions & 10 deletions lib/routes/cna/index.js → lib/v2/cna/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
ctx.params.id = ctx.params.id || 'aall';
const id = ctx.params.id || 'aall';

let rootUrl;

if (/^\d+$/.test(ctx.params.id)) {
rootUrl = `https://www.cna.com.tw/topic/newstopic/${ctx.params.id}.aspx`;
if (/^\d+$/.test(id)) {
rootUrl = `https://www.cna.com.tw/topic/newstopic/${id}.aspx`;
} else {
rootUrl = `https://www.cna.com.tw/list/${ctx.params.id}.aspx`;
rootUrl = `https://www.cna.com.tw/list/${id}.aspx`;
}
const response = await got({
method: 'get',
url: rootUrl,
});

const $ = cheerio.load(response.data);
const list = $('#jsMainList li a div h2')
.slice(0, 10)
.map((_, item) => {
const list = $('.mainList li a div h2')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 10)
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.parents('a').attr('href'),
pubDate: new Date(item.next().text() + ' GMT+8').toUTCString(),
pubDate: timezone(parseDate(item.next().text()), +8),
};
})
.get();
});

const items = await Promise.all(
list.map((item) =>
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/cna/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:id?': ['nczitzk'],
};
13 changes: 13 additions & 0 deletions lib/v2/cna/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'cna.com.tw': {
_name: '中央通訊社',
'.': [
{
title: '分类',
docs: 'https://docs.rsshub.app/routes/traditional-media#zhong-yang-tong-xun-she',
source: ['/list/:id', '/topic/newstopic/:id'],
target: (params) => `/cna/${params.id.replace('.aspx', '')}`,
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/cna/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:id?', require('./'));
};
24 changes: 12 additions & 12 deletions website/docs/routes/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -2339,18 +2339,6 @@ category 对应的关键词有

</Route>

## 台湾中央通讯社 {#tai-wan-zhong-yang-tong-xun-she}

### 分类 {#tai-wan-zhong-yang-tong-xun-she-fen-lei}

<Route author="nczitzk" example="/cna/aall" path="/cna/:id?" paramsDesc={['分类 id 或新闻专题 id。分类 id 见下表,新闻专题 id 為 https://www.cna.com.tw/list/newstopic.aspx 中,連結的數字部份。此參數默认为 aall']}>

| 即時 | 政治 | 國際 | 兩岸 | 產經 | 證券 | 科技 | 生活 | 社會 | 地方 | 文化 | 運動 | 娛樂 |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| aall | aipl | aopl | acn | aie | asc | ait | ahel | asoc | aloc | acul | aspt | amov |

</Route>

## 天下雜誌 {#tian-xia-za-zhi}

### 最新上線 {#tian-xia-za-zhi-zui-xin-shang-xian}
Expand Down Expand Up @@ -2772,6 +2760,18 @@ category 对应的关键词有

</Route>

## 中央通讯社 {#zhong-yang-tong-xun-she}

### 分类 {#zhong-yang-tong-xun-she-fen-lei}

<Route author="nczitzk" example="/cna/aall" path="/cna/:id?" paramsDesc={['分类 id 或新闻专题 id。分类 id 见下表,新闻专题 id 為 https://www.cna.com.tw/list/newstopic.aspx 中,連結的數字部份。此參數默认为 aall']}>

| 即時 | 政治 | 國際 | 兩岸 | 產經 | 證券 | 科技 | 生活 | 社會 | 地方 | 文化 | 運動 | 娛樂 |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| aall | aipl | aopl | acn | aie | asc | ait | ahel | asoc | aloc | acul | aspt | amov |

</Route>

## 组织人事报 {#zu-zhi-ren-shi-bao}

### 电子报 {#zu-zhi-ren-shi-bao-dian-zi-bao}
Expand Down

0 comments on commit 64839f0

Please sign in to comment.