Skip to content

Commit

Permalink
fix(route): caixin weekly (#15364)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Apr 24, 2024
1 parent 768e991 commit 8a11f0e
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions lib/routes/caixin/weekly.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Route } from '@/types';
import { DataItem, Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
Expand All @@ -8,15 +8,6 @@ export const route: Route = {
path: '/weekly',
categories: ['traditional-media'],
example: '/caixin/weekly',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['weekly.caixin.com/', 'weekly.caixin.com/*'],
Expand All @@ -38,16 +29,16 @@ async function handler(ctx) {
...$('.mi')
.toArray()
.map((item) => ({
link: $(item).find('a').attr('href'),
link: $(item).find('a').attr('href')?.replace('http:', 'https:'),
})),
...$('.xsjCon a')
.toArray()
.map((item) => ({
link: $(item).attr('href'),
})),
].slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 10);
].slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 10) as DataItem[];

const items = await Promise.all(
const items = (await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const { data } = await got(item.link);
Expand All @@ -73,7 +64,7 @@ async function handler(ctx) {
return item;
})
)
);
)) as DataItem[];

return {
title: $('head title')
Expand Down

0 comments on commit 8a11f0e

Please sign in to comment.