Skip to content

Commit

Permalink
fix(route/zaobao): Adapt to new SG layout (DIYgod#17902)
Browse files Browse the repository at this point in the history
* fix(route/zaobao): Replace `got` while fetching article list

* .

* Update util.ts

* Update util.ts
  • Loading branch information
dzx-dzx authored Dec 17, 2024
1 parent 6e5738e commit 9371b89
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/routes/zaobao/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,22 @@ const parseList = async (
const article = await got_ins.get(link);
const $1 = load(article.data);

const time = (() =>
$1("head script[type='application/json']").text() === ''
? new Date(JSON.parse($1("head script[type='application/ld+json']").eq(1).text())?.datePublished) // HK
: new Date(Number(JSON.parse($1("head script[type='application/json']").text())?.articleDetails?.created) * 1000))(); // SG
let title, time;
if ($1('#seo-article-page').text() === '') {
// HK
title = $1('h1.article-title').text();
time = new Date(JSON.parse($1("head script[type='application/ld+json']").eq(1).text())?.datePublished);
} else {
// SG
title = JSON.parse($1('#seo-article-page').text())['@graph'][0]?.headline;
time = new Date(JSON.parse($1('#seo-article-page').text())['@graph'][0]?.datePublished);
}

$1('.overlay-microtransaction').remove();
$1('#video-freemium-player').remove();
$1('script').remove();

let articleBodyNode = $1('.article-content-rawhtml');
let articleBodyNode = $1('.articleBody');
if (articleBodyNode.length === 0) {
// for HK version
orderContent($1('.article-body'));
Expand All @@ -107,8 +113,8 @@ const parseList = async (
const imageDataArray = processImageData($1);

return {
// <- for SG version -> for HK version
title: $1('h1', '.content').text().trim() || $1('h1.article-title').text(),
// <- for HK version -> for SG version
title,
description: art(path.join(__dirname, 'templates/zaobao.art'), {
articleBody,
imageDataArray,
Expand Down

0 comments on commit 9371b89

Please sign in to comment.