From fe4f6505d5d29120950b8f9895952ba8e2d3d2a1 Mon Sep 17 00:00:00 2001 From: Felix Hsu Date: Wed, 2 Nov 2022 20:11:05 +0800 Subject: [PATCH] fix(route): thepaper pic list feature page error (#11198) * 1. fix timezone shift 2. add podcast for voice article 3.use list icon for list feed 4. category support * extract logo using cheerio * fix the fallback logo image on list feed * fix the deepscan insufficient null checking * add support for album type article * video playback not working correctly on weixin * fix thepaper pic list * fix thepaper pic list deepscan --- lib/v2/thepaper/utils.js | 102 ++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/lib/v2/thepaper/utils.js b/lib/v2/thepaper/utils.js index f69f1ea6e..97ec927e4 100644 --- a/lib/v2/thepaper/utils.js +++ b/lib/v2/thepaper/utils.js @@ -5,69 +5,73 @@ const { art } = require('@/utils/render'); const timezone = require('@/utils/timezone'); const path = require('path'); +const defaultRssItem = (item) => ({ + title: item.name, + link: item.link, + description: item.name, + pubDate: timezone(parseDate(item.pubTimeLong), +8), + media: { + content: { + url: item.pic, + }, + }, +}); + module.exports = { ProcessItem: async (item, ctx) => { if (item.link) { // external link - return { - title: item.name, - link: item.link, - description: item.name, - pubDate: timezone(parseDate(item.pubTimeLong), +8), - media: { - content: { - url: item.pic, - }, - }, - }; + return defaultRssItem(item); } else { const itemUrl = `https://m.thepaper.cn/detail/${item.contId}`; return await ctx.cache.tryGet(itemUrl, async () => { const res = await got(itemUrl); const data = JSON.parse(cheerio.load(res.data)('#__NEXT_DATA__').html()); const detailData = data.props.pageProps.detailData; + const contentDetail = detailData.contentDetail || detailData.liveDetail || detailData.specialDetail?.specialInfo; + if (contentDetail) { + let description = contentDetail.content || contentDetail.summary || contentDetail.desc || ''; - const contentDetail = detailData.contentDetail || detailData.liveDetail; - let description = contentDetail.content || contentDetail.summary || ''; + if (contentDetail.videos) { + description = + art(path.join(__dirname, 'templates/video_detail.art'), { + // see https://nanmu.me/zh-cn/posts/2020/strange-html-video-tag-behavior-in-wechat/ + // for video tag details + videos: contentDetail.videos, + }) + description; + } + if (contentDetail.images) { + description = + art(path.join(__dirname, 'templates/image_detail.art'), { + images: contentDetail.images, + }) + description; + } - if (contentDetail.videos) { - description = - art(path.join(__dirname, 'templates/video_detail.art'), { - // see https://nanmu.me/zh-cn/posts/2020/strange-html-video-tag-behavior-in-wechat/ - // for video tag details - videos: contentDetail.videos, - }) + description; - } - - if (contentDetail.images) { - description = - art(path.join(__dirname, 'templates/image_detail.art'), { - images: contentDetail.images, - }) + description; - } - - const rss_item = { - title: contentDetail.name, - link: itemUrl, - description, - category: contentDetail.tagList?.map((t) => t.tag) ?? [], - pubDate: timezone(parseDate(item.pubTimeLong || contentDetail.pubTime), +8), - author: contentDetail.author, - media: { - content: { - url: item.pic || contentDetail.videos?.coverUrl, + const rss_item = { + title: contentDetail.name || contentDetail.shareName, + link: itemUrl, + description, + category: contentDetail.tagList?.map((t) => t.tag) ?? [], + pubDate: timezone(parseDate(item.pubTimeLong || contentDetail.pubTime || contentDetail.publishTime), +8), + author: contentDetail.author || '', + media: { + content: { + url: item.pic || contentDetail.videos?.coverUrl || contentDetail.bigPic, + }, + thumbnails: { + url: item.sharePic || contentDetail.sharePic, + }, }, - thumbnails: { - url: item.sharePic || contentDetail.sharePic, - }, - }, - }; - if (contentDetail.voiceInfo?.isHaveVoice) { - rss_item.enclosure_type = 'audio/mpeg'; - rss_item.enclosure_url = contentDetail.voiceInfo.voiceSrc; - rss_item.itunes_item_image = item.pic || contentDetail.videos?.coverUrl; + }; + if (contentDetail.voiceInfo?.isHaveVoice) { + rss_item.enclosure_type = 'audio/mpeg'; + rss_item.enclosure_url = contentDetail.voiceInfo.voiceSrc; + rss_item.itunes_item_image = item.pic || contentDetail.videos?.coverUrl; + } + return rss_item; + } else { + return defaultRssItem(item); } - return rss_item; }); } },