refactor: refactor thepaper utils for optimize rss reading (#10859)
* 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
This commit is contained in:
parent
4aaed3561c
commit
b053af1050
|
|
@ -14,5 +14,7 @@ module.exports = async (ctx) => {
|
|||
title: `澎湃新闻频道 - ${utils.ChannelIdToName(id, data)}`,
|
||||
link: channel_url,
|
||||
item: items,
|
||||
itunes_author: '澎湃新闻',
|
||||
image: utils.ExtractLogo(response),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,10 +8,11 @@ module.exports = async (ctx) => {
|
|||
const list = data.props.pageProps.data.list;
|
||||
|
||||
const items = await Promise.all(list.map((item) => utils.ProcessItem(item, ctx)));
|
||||
|
||||
ctx.state.data = {
|
||||
title: '澎湃新闻 - 首页头条',
|
||||
link: 'https://m.thepaper.cn',
|
||||
item: items,
|
||||
itunes_author: '澎湃新闻',
|
||||
image: utils.ExtractLogo(response),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,13 +7,15 @@ module.exports = async (ctx) => {
|
|||
const list_url = `https://m.thepaper.cn/list/${id}`;
|
||||
const response = await got(list_url);
|
||||
const data = JSON.parse(cheerio.load(response.data)('#__NEXT_DATA__').html());
|
||||
const list = data.props.pageProps.data.list;
|
||||
const pagePropsData = data.props.pageProps.data;
|
||||
const list = pagePropsData.list;
|
||||
|
||||
const items = await Promise.all(list.map((item) => utils.ProcessItem(item, ctx)));
|
||||
|
||||
ctx.state.data = {
|
||||
title: `澎湃新闻栏目 - ${utils.ListIdToName(id, data)}`,
|
||||
link: list_url,
|
||||
item: items,
|
||||
itunes_author: '澎湃新闻',
|
||||
image: pagePropsData.nodeInfo?.pic ?? utils.ExtractLogo(response),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
{{ each images }}
|
||||
<figure class="wp-block-image size-full">
|
||||
<img width="{{ $value.width }}" src="{{ $value.src }}">
|
||||
</figure>
|
||||
<p>{{ $value.description }}</p>
|
||||
{{ /each }}
|
||||
|
|
@ -2,6 +2,7 @@ const cheerio = require('cheerio');
|
|||
const { parseDate } = require('@/utils/parse-date');
|
||||
const got = require('@/utils/got');
|
||||
const { art } = require('@/utils/render');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
|
|
@ -12,7 +13,7 @@ module.exports = {
|
|||
title: item.name,
|
||||
link: item.link,
|
||||
description: item.name,
|
||||
pubDate: parseDate(item.pubTimeLong),
|
||||
pubDate: timezone(parseDate(item.pubTimeLong), +8),
|
||||
media: {
|
||||
content: {
|
||||
url: item.pic,
|
||||
|
|
@ -27,7 +28,7 @@ module.exports = {
|
|||
const detailData = data.props.pageProps.detailData;
|
||||
|
||||
const contentDetail = detailData.contentDetail || detailData.liveDetail;
|
||||
let description = contentDetail.content || contentDetail.summary;
|
||||
let description = contentDetail.content || contentDetail.summary || '';
|
||||
|
||||
if (contentDetail.videos) {
|
||||
description =
|
||||
|
|
@ -36,21 +37,35 @@ module.exports = {
|
|||
}) + description;
|
||||
}
|
||||
|
||||
return {
|
||||
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,
|
||||
pubDate: parseDate(contentDetail.pubTime),
|
||||
category: contentDetail.tagList?.map((t) => t.tag) ?? [],
|
||||
pubDate: timezone(parseDate(item.pubTimeLong || contentDetail.pubTime), +8),
|
||||
author: contentDetail.author,
|
||||
media: {
|
||||
content: {
|
||||
url: item.pic || contentDetail.sharePic || (contentDetail.videos && contentDetail.videos.coverUrl),
|
||||
url: item.pic || contentDetail.videos?.coverUrl,
|
||||
},
|
||||
thumbnails: {
|
||||
url: item.pic || contentDetail.sharePic,
|
||||
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;
|
||||
}
|
||||
return rss_item;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
@ -67,4 +82,5 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
},
|
||||
ExtractLogo: (response) => 'https://m.thepaper.cn' + cheerio.load(response.data)('img.imageCover').attr('src'),
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue