fix(route/apnews): Fix page (#15808)

* fix(route/apnews): Fix page.

* .
This commit is contained in:
Andvari 2024-06-04 01:14:04 +08:00 committed by GitHub
parent 7175ab0fdd
commit 4cf8b284f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -43,7 +43,7 @@ async function handler(ctx) {
link: $(e).find('a').attr('href'),
}))
.filter((e) => typeof e.link === 'string')
.map((item) => (new URL(item.link).hostname === 'apnews.com' ? fetchArticle(item) : item))
.map((item) => fetchArticle(item))
);
return {

View File

@ -7,6 +7,9 @@ export function fetchArticle(item) {
return cache.tryGet(item.link, async () => {
const data = await ofetch(item.link);
const $ = load(data);
if ($('#link-ld-json').length === 0) {
return item;
}
const rawLdjson = JSON.parse($('#link-ld-json').text());
let ldjson;
if (Array.isArray(rawLdjson)) {