From 1418f35d7bf5dd837135e4a1c419dde1c8f94e8a Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Sat, 14 Sep 2024 23:07:26 +0800 Subject: [PATCH] feat(route/apnews): Enhance parsing when not fetching full text. (#16750) --- lib/routes/apnews/api.ts | 7 ++++++- lib/routes/apnews/sitemap.ts | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/routes/apnews/api.ts b/lib/routes/apnews/api.ts index fffed46252da09..28d7e0f4f01370 100644 --- a/lib/routes/apnews/api.ts +++ b/lib/routes/apnews/api.ts @@ -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', }; } diff --git a/lib/routes/apnews/sitemap.ts b/lib/routes/apnews/sitemap.ts index 4102d5e1076bc7..07d89f9fda28bb 100644 --- a/lib/routes/apnews/sitemap.ts +++ b/lib/routes/apnews/sitemap.ts @@ -87,6 +87,7 @@ async function handler(ctx) { return { title: `AP News sitemap:${route}`, item: items, + link: 'https://apnews.com', }; } async function asyncPoolAll(poolLimit: number, array: readonly IN[], iteratorFn: (generator: IN) => Promise) {