Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(routes/cctv/xwlb): add detail content for each news #18212

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions lib/routes/cctv/xwlb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const route: Route = {
},
],
name: '新闻联播',
maintainers: ['zengxs'],
maintainers: ['zengxs', 'cscnk52'],
handler,
url: 'tv.cctv.com/lm/xwlb',
description: `新闻联播内容摘要。`,
Expand Down Expand Up @@ -75,14 +75,21 @@ const getXWLB = async () => {
const res = await got(url);
const content = load(res.data);
const list: string[] = [];
content('body li').map((i, elem) => {
const e = content(elem);
const href = e.find('a').attr('href');
const title = e.find('a').attr('title');
const dur = e.find('span').text();
list.push(`<a href="${href}">${title} ⏱${dur}</a>`);
return i;
});
await Promise.all(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dramatically increase the number of HTTP requests required from 21 to 321 which is a big NO.

content('body li').map(async (i, elem) => {
const e = content(elem);
const href = e.find('a').attr('href');
const title = e.find('a').attr('title');
const dur = e.find('span').text();

const detailPage = await got(href);
const detailContent = load(detailPage.data);
const detail = detailContent('div.content_area').html();

list.push(`<a href="${href}">${title} ⏱${dur}</a>${detail}`);
return i;
})
);
return list.join('<br/>\n');
}),
};
Expand Down
Loading