From 9371b8977924983de51c7d101c91c741305d0d52 Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:40:34 +0800 Subject: [PATCH] fix(route/zaobao): Adapt to new SG layout (#17902) * fix(route/zaobao): Replace `got` while fetching article list * . * Update util.ts * Update util.ts --- lib/routes/zaobao/util.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/routes/zaobao/util.ts b/lib/routes/zaobao/util.ts index 4de18e3a57ecd8..f2d8edf783626b 100644 --- a/lib/routes/zaobao/util.ts +++ b/lib/routes/zaobao/util.ts @@ -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')); @@ -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,