feat: add 凤凰网-大风号 (#3924)
This commit is contained in:
@@ -393,6 +393,16 @@ Supported sub-sites:
|
||||
|
||||
<Route author="emdoe" example="/plainlaw/archives" path="/plainlaw/archives"/>
|
||||
|
||||
## 凤凰网
|
||||
|
||||
### 大风号
|
||||
|
||||
<Route author="Jamch" example="/ifeng/feng/2583/doc" path="/ifeng/feng/:id/:type" :paramsDesc="['对应 id,可在 大风号作者页面 找到','类型,见下表']"/>
|
||||
|
||||
| 文章 | 视频 |
|
||||
| ---- | ----- |
|
||||
| doc | video |
|
||||
|
||||
## 观察者网-中国关怀 全球视野
|
||||
|
||||
### 观察者首页
|
||||
|
||||
@@ -2201,6 +2201,9 @@ router.get('/lastfm/top/:country?', require('./routes/lastfm/top'));
|
||||
router.get('/piapro/user/:pid', require('./routes/piapro/user'));
|
||||
router.get('/piapro/public/:type/:tag?/:category?', require('./routes/piapro/public'));
|
||||
|
||||
// 凤凰网
|
||||
router.get('/ifeng/feng/:id/:type', require('./routes/ifeng/feng'));
|
||||
|
||||
// 网易公开课
|
||||
router.get('/open163/vip', require('./routes/netease/open/vip'));
|
||||
router.get('/open163/latest', require('./routes/netease/open/latest'));
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { JSDOM } = require('jsdom');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const type = ctx.params.type;
|
||||
const userResponse = await got({
|
||||
method: 'get',
|
||||
url: `https://shankapi.ifeng.com/winter/ishare/getAccountInfo/${id}`,
|
||||
headers: {
|
||||
Referer: `https://ishare.ifeng.com/mediaShare/home/${id}/do`,
|
||||
},
|
||||
});
|
||||
const contentResponse = await got({
|
||||
method: 'get',
|
||||
url: `https://shankapi.ifeng.com/winter/ishare/getShareListData/${id}/${type}/1`,
|
||||
headers: {
|
||||
Referer: `https://ishare.ifeng.com/mediaShare/home/${id}/do`,
|
||||
},
|
||||
});
|
||||
|
||||
const userData = userResponse.data.data.data;
|
||||
const contentData = contentResponse.data.data;
|
||||
|
||||
const mediaName = userData.weMediaName;
|
||||
const items = await Promise.all(
|
||||
(contentData || []).map(async (item) => {
|
||||
const link = `https://feng.ifeng.com/c/${item.id}`;
|
||||
const simple = {
|
||||
title: item.title,
|
||||
description: `<img src="${item.thumbnail}">${item.title}`,
|
||||
pubDate: new Date(Date.parse(item.newsTime.replace(/-/g, '/'))),
|
||||
author: mediaName,
|
||||
link: link,
|
||||
};
|
||||
|
||||
const details = await ctx.cache.tryGet(`ifeng:feng:${link}`, async () => {
|
||||
const response = await got.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
if (type === 'doc') {
|
||||
const dom = new JSDOM(`<body><script>${$('#__INITIAL_STATE__').html()}</script></body>`, {
|
||||
runScripts: 'dangerously',
|
||||
});
|
||||
const data = dom.window.allData;
|
||||
return {
|
||||
description: utils.extractDoc(data),
|
||||
};
|
||||
}
|
||||
if (type === 'video') {
|
||||
return {
|
||||
description: `<img src="${item.thumbnail}"><br><video src="${$('meta[name=og\\:img_video]').attr('content')}">`,
|
||||
};
|
||||
}
|
||||
return {
|
||||
description: $('meta[name=description]').attr('content'),
|
||||
};
|
||||
});
|
||||
return Promise.resolve(Object.assign({}, simple, details));
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `大风号-${mediaName}-${type === 'doc' ? '文章' : '视频'}`,
|
||||
link: `https://feng.ifeng.com/author/${id}`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
const extractDoc = (data) => {
|
||||
if (data.docData.contentData.contentList) {
|
||||
return extractContent(data.docData.contentData.contentList);
|
||||
}
|
||||
if (data.docData.contentData.image) {
|
||||
return data.docData.contentData.image.map((item) => `<p><img src="${item.url}"><br>${item.description.replace(/\n/g, '<br>')}</p>`).join('');
|
||||
}
|
||||
};
|
||||
|
||||
const extractContent = (data) =>
|
||||
(data || [])
|
||||
.map((item) => {
|
||||
const type = item.type;
|
||||
if (type === 'video') {
|
||||
return `<video src="${item.data.mobileUrl}">`;
|
||||
}
|
||||
if (type === 'text') {
|
||||
return item.data;
|
||||
}
|
||||
return '';
|
||||
})
|
||||
.join('<br>');
|
||||
|
||||
module.exports = {
|
||||
extractDoc,
|
||||
};
|
||||
Reference in New Issue
Block a user