feat(route/apnews): Expand range of application (#16355)

* feat(route/apnews): Expand range of application

* .
This commit is contained in:
Andvari
2024-10-19 17:50:21 +08:00
committed by GitHub
parent 27c56bb4b8
commit 57b7cc39ac
+4 -3
View File
@@ -5,7 +5,7 @@ import { fetchArticle, removeDuplicateByKey } from './utils';
const HOME_PAGE = 'https://apnews.com';
export const route: Route = {
path: '/topics/:topic?',
path: ['/topics/:topic?', '/nav/:nav{.*}?'],
categories: ['traditional-media', 'popular'],
example: '/apnews/topics/apf-topnews',
view: ViewType.Articles,
@@ -35,8 +35,9 @@ export const route: Route = {
};
async function handler(ctx) {
const { topic = 'trending-news' } = ctx.req.param();
const url = `${HOME_PAGE}/hub/${topic}`;
const { topic = 'trending-news', nav = '' } = ctx.req.param();
const useNav = ctx.req.routePath === '/apnews/nav/:nav{.*}?';
const url = useNav ? `${HOME_PAGE}/${nav}` : `${HOME_PAGE}/hub/${topic}`;
const response = await got(url);
const $ = load(response.data);