From eb467afae1d70e7c410bdd27bec08bdf5b85795e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E5=B9=B3=E7=94=9F?= Date: Fri, 15 Apr 2022 19:23:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(utils):=20=E6=94=AF=E6=8C=81=E5=B0=86?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=85=AC=E4=BC=97=E5=8F=B7=E8=BD=AC=E8=BD=BD?= =?UTF-8?q?=E6=96=87=E7=AB=A0=E7=9A=84=E6=AD=A3=E6=96=87=E6=8A=93=E5=8F=96?= =?UTF-8?q?=E5=9B=9E=E6=9D=A5=20(#9534)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 修正日期时间匹配规则、移除一些不必要评论元素 * fix(route)(fortunechina): 修正财富中文网1、双语文章中文内容重复问题;2、移除 kol 大头像 * fix(route)(wechat): 支持将微信公众号转载文章的正文抓取回来 --- lib/utils/wechat-mp.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/utils/wechat-mp.js b/lib/utils/wechat-mp.js index 8e3278019..96723029c 100644 --- a/lib/utils/wechat-mp.js +++ b/lib/utils/wechat-mp.js @@ -35,6 +35,18 @@ const replaceTag = ($, oldTag, newTagName) => { oldTag.replaceWith(NewTag); }; +const detectOriginalArticleUrl = ($) => { + // No article content get, try the original url + if (!$('#js_content').text()) { + return $('#js_share_source').attr('data-url'); + } + // Article content is too short, try the first link + if ($('#js_content').text().length < 80) { + return $('#js_content a').attr('href'); + } + return null; +}; + /** * Articles from WeChat MP have weird formats, this function is used to fix them. * @@ -147,7 +159,16 @@ const fetchArticle = async (ctx, url, bypassHostCheck = false) => { const author = $('meta[name=author]').attr('content'); let summary = $('meta[name=description]').attr('content'); summary = summary !== title ? summary : ''; - const description = fixArticleContent($('div#js_content.rich_media_content')); + let description = fixArticleContent($('div#js_content.rich_media_content')); + + // No article get or article is too short, try the original url + const originalUrl = detectOriginalArticleUrl($); + if (originalUrl) { + // try to fetch the description from the original article + const originalResponse = await got(normalizeUrl(originalUrl, bypassHostCheck)); + const original$ = cheerio.load(originalResponse.data); + description += fixArticleContent(original$('#js_content')); + } let pubDate; const publish_time_script = $('script[nonce][type="text/javascript"]:contains("var ct")').first().html();