Skip to content

Commit 5ae169a

Browse files
authored
feat(route/cna): support headlines (#21053)
* feat(route/cna): declare headlines as supported https://www.cna.com.tw/list/headlines.aspx works the same as other categories (aall, aipl, ...) - the same HTML structure and API * fix(route/cna): ignore youtube links during full-text extraction Sometimes a youtube link instead of a news page is used directly as a news item (ex: 晚間影音新聞 during 6~7pm UTC+8 on weekdays). That may result in HTTP 429. Full-text extraction returns nothing, anyway. * fix(route/cna): note about where the API is from
1 parent 55ca8bb commit 5ae169a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/routes/cna/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ export const route: Route = {
2222
name: '分类',
2323
maintainers: ['nczitzk'],
2424
handler,
25-
description: `| 即時 | 政治 | 國際 | 兩岸 | 產經 | 證券 | 科技 | 生活 | 社會 | 地方 | 文化 | 運動 | 娛樂 |
26-
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
27-
| aall | aipl | aopl | acn | aie | asc | ait | ahel | asoc | aloc | acul | aspt | amov |`,
25+
description: `| 聚焦 | 即時 | 政治 | 國際 | 兩岸 | 產經 | 證券 | 科技 | 生活 | 社會 | 地方 | 文化 | 運動 | 娛樂 |
26+
| --------- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
27+
| headlines | aall | aipl | aopl | acn | aie | asc | ait | ahel | asoc | aloc | acul | aspt | amov |`,
2828
};
2929

3030
async function handler(ctx) {
3131
const id = ctx.req.param('id') || 'aall';
3232
const isTopic = /^\d+$/.test(id);
3333
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20;
3434

35+
// The API used by the website when hitting "看更多內容"
3536
const { data: response } = await got({
3637
method: 'post',
3738
url: `https://www.cna.com.tw/cna2018api/api/${isTopic ? 'WTopic' : 'WNewsList'}`,

lib/routes/cna/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { load } from 'cheerio';
33
import got from '@/utils/got';
44

55
export async function getFullText(item) {
6+
if (item.link.startsWith('https://www.youtube.com/')) {
7+
return item;
8+
}
9+
610
const detailResponse = await got({
711
method: 'get',
812
url: item.link,

0 commit comments

Comments
 (0)