Skip to content

Commit

Permalink
feat(route/apnews): Enhance parsing when not fetching full text. (#16750
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dzx-dzx committed Sep 14, 2024
1 parent 0605590 commit 1418f35
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/routes/apnews/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,19 @@ async function handler(ctx) {
title: e.contents[0]?.headline,
link: e.contents[0]?.localLinkUrl,
pubDate: timezone(parseDate(e.publishedDate), 0),
category: e.tagObjs.map((tag) => tag.name),
updated: timezone(parseDate(e.contents[0]?.updated), 0),
description: e.contents[0]?.storyHTML,
author: e.contents[0]?.reporters.map((author) => ({ name: author.displayName })),
}))
.sort((a, b) => b.pubDate - a.pubDate)
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20);

const items = await Promise.all(list.map((item) => fetchArticle(item)));
const items = ctx.req.query('mode') === 'fulltext' ? await Promise.all(list.map((item) => fetchArticle(item))) : list;

return {
title: `${res.tagObjs[0].name} - AP News`,
item: items,
link: 'https://apnews.com',
};
}
1 change: 1 addition & 0 deletions lib/routes/apnews/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ async function handler(ctx) {
return {
title: `AP News sitemap:${route}`,
item: items,
link: 'https://apnews.com',
};
}
async function asyncPoolAll<IN, OUT>(poolLimit: number, array: readonly IN[], iteratorFn: (generator: IN) => Promise<OUT>) {
Expand Down

0 comments on commit 1418f35

Please sign in to comment.