Skip to content

Commit

Permalink
fix(route/apnews): Adapt to live page. (DIYgod#15795)
Browse files Browse the repository at this point in the history
* fix(route/apnews): Adapt to live page.

* .
  • Loading branch information
dzx-dzx authored Jun 3, 2024
1 parent 0da7f3d commit 331059c
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions lib/routes/apnews/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,33 @@ 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 {
pubDate: parseDate(ldjson.datePublished),
updated: parseDate(ldjson.dateModified),
description: $('div.RichTextStoryBody').html(),
category: [`section:${$("meta[property='article:section']").attr('content')}`, ...ldjson.keywords],
guid: $("meta[name='brightspot.contentId']").attr('content'),
author: ldjson.author,
...item,
};
const rawLdjson = JSON.parse($('#link-ld-json').text());
let ldjson;
if (Array.isArray(rawLdjson)) {
// Regular
ldjson = rawLdjson[0];

$('div.Enhancement').remove();
return {
pubDate: parseDate(ldjson.datePublished),
updated: parseDate(ldjson.dateModified),
description: $('div.RichTextStoryBody').html(),
category: [`section:${$("meta[property='article:section']").attr('content')}`, ...ldjson.keywords],
guid: $("meta[name='brightspot.contentId']").attr('content'),
author: ldjson.author,
...item,
};
} else {
// Live
ldjson = rawLdjson;

return {
category: ldjson.keywords,
pubDate: parseDate(ldjson.coverageStartTime),
description: ldjson.description,
guid: $("meta[name='brightspot.contentId']").attr('content'),
...item,
};
}
});
}

0 comments on commit 331059c

Please sign in to comment.