diff --git a/lib/v2/thepaper/channel.js b/lib/v2/thepaper/channel.js index 4a22c8414..0f1c4dc8c 100644 --- a/lib/v2/thepaper/channel.js +++ b/lib/v2/thepaper/channel.js @@ -14,5 +14,7 @@ module.exports = async (ctx) => { title: `澎湃新闻频道 - ${utils.ChannelIdToName(id, data)}`, link: channel_url, item: items, + itunes_author: '澎湃新闻', + image: utils.ExtractLogo(response), }; }; diff --git a/lib/v2/thepaper/featured.js b/lib/v2/thepaper/featured.js index bb237b9fe..455f924e1 100644 --- a/lib/v2/thepaper/featured.js +++ b/lib/v2/thepaper/featured.js @@ -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), }; }; diff --git a/lib/v2/thepaper/list.js b/lib/v2/thepaper/list.js index 06c417c7f..0712f9dc3 100644 --- a/lib/v2/thepaper/list.js +++ b/lib/v2/thepaper/list.js @@ -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), }; }; diff --git a/lib/v2/thepaper/templates/image_detail.art b/lib/v2/thepaper/templates/image_detail.art new file mode 100644 index 000000000..559419ce1 --- /dev/null +++ b/lib/v2/thepaper/templates/image_detail.art @@ -0,0 +1,6 @@ +{{ each images }} +
+ +
+

{{ $value.description }}

+{{ /each }} diff --git a/lib/v2/thepaper/utils.js b/lib/v2/thepaper/utils.js index a96b03fd5..3a5aca4de 100644 --- a/lib/v2/thepaper/utils.js +++ b/lib/v2/thepaper/utils.js @@ -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'), };