From 4e31222c137aa493194cec95af8a54cd36ea41fd Mon Sep 17 00:00:00 2001 From: Enoch Ma Date: Fri, 30 Oct 2020 17:44:38 +0800 Subject: [PATCH] feat: better compatibility fo AEON & NYTimes (#6054) --- lib/routes/aeon/category.js | 2 +- lib/routes/nytimes/index.js | 2 +- lib/routes/nytimes/morning_post.js | 2 +- lib/routes/solidot/_article.js | 27 ++++++++++++++++++--------- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/routes/aeon/category.js b/lib/routes/aeon/category.js index 7bcf506d3..256224aff 100644 --- a/lib/routes/aeon/category.js +++ b/lib/routes/aeon/category.js @@ -33,7 +33,7 @@ module.exports = async (ctx) => { let bio; const authorInfo = '.article__body__author-details > p:nth-child(2)'; if (capture(authorInfo).html() !== null) { - bio = `





` + author.trim() + ' ' + capture(authorInfo).html().trim() + `


`; + bio = `



` + author.trim() + ' ' + capture(authorInfo).html().trim() + `


`; capture('.article__inline-sidebar').remove(); } else { bio = ''; diff --git a/lib/routes/nytimes/index.js b/lib/routes/nytimes/index.js index f42b2922f..c490c262f 100644 --- a/lib/routes/nytimes/index.js +++ b/lib/routes/nytimes/index.js @@ -86,7 +86,7 @@ module.exports = async (ctx) => { const ending = /感(谢|謝);.*?cn\.letters@nytimes\.com。/g; const matching = '
'; - const formatted = '

' + matching; + const formatted = '
' + matching; single.description = result.description.replace(ending, '').split(matching).join(formatted); diff --git a/lib/routes/nytimes/morning_post.js b/lib/routes/nytimes/morning_post.js index 4c67c27c2..ea785b071 100644 --- a/lib/routes/nytimes/morning_post.js +++ b/lib/routes/nytimes/morning_post.js @@ -37,7 +37,7 @@ module.exports = async (ctx) => { const ending = /感(谢|謝);.*?cn\.letters@nytimes\.com。/g; const matching = '
'; - const formatted = '

' + matching; + const formatted = '
' + matching; item.description = result.description.replace(ending, '').split(matching).join(formatted); diff --git a/lib/routes/solidot/_article.js b/lib/routes/solidot/_article.js index 1dd9943d4..50dab2ac6 100644 --- a/lib/routes/solidot/_article.js +++ b/lib/routes/solidot/_article.js @@ -27,19 +27,28 @@ module.exports = async function get_article(url) { let date = new Date(date_str); date.setHours(date.getHours() - 8); date = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds())); + const title = $('div.block_m > div.ct_tittle > div.bg_htit > h2').text(); + const category = $('div.icon_float > a').attr('title'); + const author = $('div.talk_time > b') + .text() + .replace(/^来自(.*)部门$/g, '$1'); + $('div.ct_tittle').remove(); + $('div.talk_time').remove(); + const description = $('div.block_m') + .html() + .replace(/(href.*?)(.*?)<\/u>/g, `$1$2`) + .replace(/href="\//g, 'href="' + domain + '/') + // Preserve the not extremely disturbing donation ad + // to support the site. + .replace(/()/g, `

$1`); const item = { - title: $('div.block_m > div.ct_tittle > div.bg_htit > h2').text(), + title: title, pubDate: date.toUTCString(), - author: $('div.talk_time > b') - .text() - .replace(/^来自(.*)部门$/g, '$1'), + author: author, link: url, - description: $('div.p_mainnew') - .html() - .replace(/(href.*?)(.*?)<\/u>/g, `$1$2`) - .replace(/href="\//g, 'href="' + domain + '/'), - category: $('div.icon_float > a').attr('title'), + description: description, + category: category, }; return item; };