From 41e8bcded897acf75299f1583c7ca8676e26d0b6 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 24 May 2024 13:14:23 +0800 Subject: [PATCH] fix(route): zaobao (#15685) --- lib/routes/zaobao/interactive.ts | 13 ++----------- lib/routes/zaobao/{index.ts => other.ts} | 12 ++---------- lib/routes/zaobao/realtime.ts | 8 -------- lib/routes/zaobao/util.ts | 22 +++++++++++++--------- 4 files changed, 17 insertions(+), 38 deletions(-) rename lib/routes/zaobao/{index.ts => other.ts} (82%) diff --git a/lib/routes/zaobao/interactive.ts b/lib/routes/zaobao/interactive.ts index 2cc01cd62dc931..e2b3a624cb7d58 100644 --- a/lib/routes/zaobao/interactive.ts +++ b/lib/routes/zaobao/interactive.ts @@ -6,27 +6,18 @@ export const route: Route = { path: '/interactive-graphics', categories: ['traditional-media'], example: '/zaobao/interactive-graphics', - parameters: {}, - features: { - requireConfig: false, - requirePuppeteer: false, - antiCrawler: false, - supportBT: false, - supportPodcast: false, - supportScihub: false, - }, name: '互动新闻', maintainers: ['shunf4'], handler, }; async function handler(ctx) { - const sectionLink = `/interactive-graphics`; + const sectionLink = '/interactive-graphics'; const { resultList } = await parseList(ctx, sectionLink); return { - title: `《联合早报》互动新闻`, + title: '《联合早报》互动新闻', link: baseUrl + sectionLink, description: '新加坡、中国、亚洲和国际的即时、评论、商业、体育、生活、科技与多媒体新闻,尽在联合早报。', item: resultList, diff --git a/lib/routes/zaobao/index.ts b/lib/routes/zaobao/other.ts similarity index 82% rename from lib/routes/zaobao/index.ts rename to lib/routes/zaobao/other.ts index e7a7bc6d6c4fab..5bd482d43b686a 100644 --- a/lib/routes/zaobao/index.ts +++ b/lib/routes/zaobao/other.ts @@ -3,18 +3,10 @@ import { parseList } from './util'; const baseUrl = 'https://www.zaobao.com'; export const route: Route = { - path: '/:type?/:section?', + path: '/other/:type?/:section?', categories: ['traditional-media'], - example: '/zaobao/lifestyle/health', + example: '/zaobao/other/lifestyle/health', parameters: { type: 'https://www.zaobao.com/**lifestyle**/health 中的 **lifestyle**', section: 'https://www.zaobao.com/lifestyle/**health** 中的 **health**' }, - features: { - requireConfig: false, - requirePuppeteer: false, - antiCrawler: false, - supportBT: false, - supportPodcast: false, - supportScihub: false, - }, name: '其他栏目', maintainers: ['shunf4'], handler, diff --git a/lib/routes/zaobao/realtime.ts b/lib/routes/zaobao/realtime.ts index 2402f4087d252e..ef108de7bacf3d 100644 --- a/lib/routes/zaobao/realtime.ts +++ b/lib/routes/zaobao/realtime.ts @@ -7,14 +7,6 @@ export const route: Route = { categories: ['traditional-media'], example: '/zaobao/realtime/china', parameters: { section: '分类,缺省为 china' }, - features: { - requireConfig: false, - requirePuppeteer: false, - antiCrawler: false, - supportBT: false, - supportPodcast: false, - supportScihub: false, - }, name: '即时新闻', maintainers: ['shunf4'], handler, diff --git a/lib/routes/zaobao/util.ts b/lib/routes/zaobao/util.ts index 8bd5a2a40d9855..4beab5d7d57178 100644 --- a/lib/routes/zaobao/util.ts +++ b/lib/routes/zaobao/util.ts @@ -22,16 +22,20 @@ const got_ins = got.extend({ * * @param {*} ctx RSSHub 的 ctx 参数,用来设置缓存 * @param {string} sectionUrl 形如 /realtime/china 的字符串 - * @returns {Promise<{ - * title: string; - * resultList: { - * title: string; - * description: string; - * pubDate: string; - * link: string; - * }[];}>} 新闻标题以及新闻列表 + * @returns 新闻标题以及新闻列表 */ -const parseList = async (ctx, sectionUrl) => { +const parseList = async ( + ctx, + sectionUrl: string +): Promise<{ + title: string; + resultList: { + title: string; + description: string; + pubDate: string; + link: string; + }[]; +}> => { const response = await got_ins.get(baseUrl + sectionUrl); const $ = load(response.data); let data = $('.article-list').find('.article-type');