feat(route/apnews): Extract data from ldjson. (#15555)

This commit is contained in:
Andvari 2024-05-12 01:45:37 +08:00 committed by GitHub
parent 8e7ec1f012
commit 1bbdbdd095
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 5 deletions

View File

@ -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,
};
});
}