feat(route): Add query parameter to control full text fetching function (#13404)
* 澎湃新闻图片及视频与正文重复 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. ---------
This commit is contained in:
parent
e5d9b5273b
commit
fcff1240e9
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -2019,6 +2019,8 @@ category 对应的关键词有
|
|||
|
||||
## 澎湃新闻 {#peng-pai-xin-wen}
|
||||
|
||||
以下所有路由可使用参数`old`以采取旧全文获取方法. 该方法会另外获取网页中的图片与视频资源. 在原始url追加`?old=yes`以启用.
|
||||
|
||||
### 首页头条 {#peng-pai-xin-wen-shou-ye-tou-tiao}
|
||||
|
||||
<Route author="HenryQW nczitzk bigfei" example="/thepaper/featured" path="/thepaper/featured"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue