diff --git a/docs/new-media.md b/docs/new-media.md index 7528d376a..2d5d0cc19 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2155,6 +2155,20 @@ Type 栏目: ## 凤凰网 +### 资讯 + + + +::: tip 提示 + +路径处填写对应页面 URL 中 `https://news.ifeng.com/` 后的字段。下面是一个例子。 + +若订阅 [大湾区\_资讯\_凤凰网](https://news.ifeng.com/shanklist/3-305565-) 则将对应页面 URL 中 `https://news.ifeng.com/` 后的字段 `shanklist/3-305565-` 作为路径填入。此时路由为 [`/ifeng/news/shanklist/3-305565-`](https://rsshub.app/ifeng/news/shanklist/3-305565-) + +::: + + + ### 大风号 diff --git a/lib/v2/ifeng/maintainer.js b/lib/v2/ifeng/maintainer.js index 45ee8780e..ca38582de 100644 --- a/lib/v2/ifeng/maintainer.js +++ b/lib/v2/ifeng/maintainer.js @@ -1,3 +1,4 @@ module.exports = { '/feng/:id/:type': ['Jamch'], + '/news/:path?': ['nczitzk'], }; diff --git a/lib/v2/ifeng/news.js b/lib/v2/ifeng/news.js new file mode 100644 index 000000000..07933c73d --- /dev/null +++ b/lib/v2/ifeng/news.js @@ -0,0 +1,54 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 20; + + const rootUrl = 'https://news.ifeng.com'; + const currentUrl = `${rootUrl}${ctx.path.replace(/^\/news/, '')}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const newsStream = JSON.parse(response.data.match(/"newsstream":(\[.*?\]),"cooperation"/)[1]); + + let items = newsStream.slice(0, limit).map((item) => ({ + title: item.title, + link: item.url, + pubDate: timezone(parseDate(item.newsTime), +8), + description: item.thumbnails.image.pop(), + })); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + item.author = detailResponse.data.match(/"editorName":"(.*?)",/)[1]; + item.category = detailResponse.data.match(/},"keywords":"(.*?)",/)[1].split(','); + item.description = art(path.join(__dirname, 'templates/description.art'), { + image: item.description, + description: JSON.parse(detailResponse.data.match(/"contentList":(\[.*?\]),/)[1]).map((content) => content.data), + }); + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/ifeng/radar.js b/lib/v2/ifeng/radar.js index a07c0aa26..cce259050 100644 --- a/lib/v2/ifeng/radar.js +++ b/lib/v2/ifeng/radar.js @@ -7,5 +7,12 @@ module.exports = { docs: 'https://docs.rsshub.app/new-media.html#feng-huang-wang', }, ], + news: [ + { + title: '资讯', + docs: 'https://docs.rsshub.app/new-media.html#feng-huang-wang-zi-xun', + target: (params, url) => `/ifeng/news${new URL(url).toString().match(/ifeng\.com(.*?)$/)[1]}`, + }, + ], }, }; diff --git a/lib/v2/ifeng/router.js b/lib/v2/ifeng/router.js index 64543af87..a568e2779 100644 --- a/lib/v2/ifeng/router.js +++ b/lib/v2/ifeng/router.js @@ -1,3 +1,4 @@ module.exports = (router) => { router.get('/feng/:id/:type', require('./feng')); + router.get(/news([\w-/]+)?/, require('./news')); }; diff --git a/lib/v2/ifeng/templates/description.art b/lib/v2/ifeng/templates/description.art new file mode 100644 index 000000000..6e8aef870 --- /dev/null +++ b/lib/v2/ifeng/templates/description.art @@ -0,0 +1,16 @@ +{{ if image }} +
+ +
+{{ /if }} +{{ if description }} +{{ each description d }} +{{ if d.attachmentType === 'video' }} + +{{ else }} +{{@ d.replace(/data-lazyload=/g, 'src=') }} +{{ /if }} +{{ /each }} +{{ /if }} \ No newline at end of file