From 1bbdbdd0951ee25ef819e6c2e98818aa35ecddc9 Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Sun, 12 May 2024 01:45:37 +0800 Subject: [PATCH] feat(route/apnews): Extract data from ldjson. (#15555) --- lib/routes/apnews/utils.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/routes/apnews/utils.ts b/lib/routes/apnews/utils.ts index 4e8b74eba..906613d4f 100644 --- a/lib/routes/apnews/utils.ts +++ b/lib/routes/apnews/utils.ts @@ -8,13 +8,16 @@ export function fetchArticle(item) { return cache.tryGet(item.link, async () => { const data = await ofetch(item.link); const $ = load(data); + const ldjson = JSON.parse($('#link-ld-json').text())[0]; $('div.Enhancement').remove(); - return Object.assign(item, { - pubDate: timezone(parseDate($("meta[property='article:published_time']").attr('content')), 0), - updated: timezone(parseDate($("meta[property='article:modified_time']").attr('content')), 0), + return { + pubDate: timezone(parseDate(ldjson.datePublished), 0), + updated: timezone(parseDate(ldjson.dateModified), 0), description: $('div.RichTextStoryBody').html(), - category: $("meta[property='article:section']").attr('content'), + category: [`section:${$("meta[property='article:section']").attr('content')}`, ...ldjson.keywords], guid: $("meta[name='brightspot.contentId']").attr('content'), - }); + author: ldjson.author, + ...item, + }; }); }