feat(route): add 凤凰网资讯 (#11026)

* feat(route): add 凤凰网资讯

* fix category
This commit is contained in:
Ethan Shen
2022-10-08 22:33:37 +08:00
committed by GitHub
parent b17f7b116f
commit fd117cb192
6 changed files with 93 additions and 0 deletions
+14
View File
@@ -2155,6 +2155,20 @@ Type 栏目:
## 凤凰网
### 资讯
<Route author="nczitzk" example="/ifeng/news" path="/ifeng/news/:path?" :paramsDesc="['路径,对应分类资讯页 URL 路径,默认为空']">
::: tip 提示
路径处填写对应页面 URL 中 `https://news.ifeng.com/` 后的字段。下面是一个例子。
若订阅 [大湾区\_资讯\_凤凰网](https://news.ifeng.com/shanklist/3-305565-) 则将对应页面 URL <https://news.ifeng.com/shanklist/3-305565-> 中 `https://news.ifeng.com/` 后的字段 `shanklist/3-305565-` 作为路径填入。此时路由为 [`/ifeng/news/shanklist/3-305565-`](https://rsshub.app/ifeng/news/shanklist/3-305565-)
:::
</Route>
### 大风号
<Route author="Jamch" example="/ifeng/feng/2583/doc" path="/ifeng/feng/:id/:type" :paramsDesc="['对应 id,可在 大风号作者页面 找到','类型,见下表']"/>
+1
View File
@@ -1,3 +1,4 @@
module.exports = {
'/feng/:id/:type': ['Jamch'],
'/news/:path?': ['nczitzk'],
};
+54
View File
@@ -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,
};
};
+7
View File
@@ -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]}`,
},
],
},
};
+1
View File
@@ -1,3 +1,4 @@
module.exports = (router) => {
router.get('/feng/:id/:type', require('./feng'));
router.get(/news([\w-/]+)?/, require('./news'));
};
+16
View File
@@ -0,0 +1,16 @@
{{ if image }}
<figure>
<img src="{{ image.url }}" height="{{ image.height }}" width="{{ image.width }}">
</figure>
{{ /if }}
{{ if description }}
{{ each description d }}
{{ if d.attachmentType === 'video' }}
<video controls poster="{{ d.bigPosterUrl }}">
<source src="{{ d.playUrl }}">
</video>
{{ else }}
{{@ d.replace(/data-lazyload=/g, 'src=') }}
{{ /if }}
{{ /each }}
{{ /if }}