From fcff1240e94cb90f523a193ad73de5d1a89196d4 Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Wed, 27 Sep 2023 19:44:28 +0800 Subject: [PATCH] feat(route): Add query parameter to control full text fetching function (#13404) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 澎湃新闻图片及视频与正文重复 Fixes #13401 * Save cache to different path for each mode. * Update website/docs/routes/traditional-media.md * Add text content to full text if the source is of video type. --------- --- lib/v2/thepaper/utils.js | 30 ++++++++++++++---------- website/docs/routes/traditional-media.md | 2 ++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/v2/thepaper/utils.js b/lib/v2/thepaper/utils.js index b71b16bf5..bf472fd0c 100644 --- a/lib/v2/thepaper/utils.js +++ b/lib/v2/thepaper/utils.js @@ -18,12 +18,13 @@ const defaultRssItem = (item) => ({ module.exports = { ProcessItem: (item, ctx) => { + const useOldMode = ctx.query.old === 'yes'; if (item.link) { // external link return defaultRssItem(item); } const itemUrl = `https://m.thepaper.cn/detail/${item.contId}`; - return ctx.cache.tryGet(itemUrl, async () => { + return ctx.cache.tryGet(`${itemUrl}${useOldMode ? ':old' : ''}`, async () => { const res = await got(itemUrl); const data = JSON.parse(cheerio.load(res.data)('#__NEXT_DATA__').html()); const detailData = data.props.pageProps.detailData; @@ -34,18 +35,23 @@ module.exports = { let description = contentDetail.content || contentDetail.summary || contentDetail.desc || ''; 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; + description = description + contentDetail.summary; } - if (contentDetail.images) { - description = - art(path.join(__dirname, 'templates/image_detail.art'), { - images: contentDetail.images, - }) + description; + if (useOldMode) { + 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 = { diff --git a/website/docs/routes/traditional-media.md b/website/docs/routes/traditional-media.md index 85996ff8a..73e8eb424 100644 --- a/website/docs/routes/traditional-media.md +++ b/website/docs/routes/traditional-media.md @@ -2019,6 +2019,8 @@ category 对应的关键词有 ## 澎湃新闻 {#peng-pai-xin-wen} +以下所有路由可使用参数`old`以采取旧全文获取方法. 该方法会另外获取网页中的图片与视频资源. 在原始url追加`?old=yes`以启用. + ### 首页头条 {#peng-pai-xin-wen-shou-ye-tou-tiao}