feat: 增加好奇怪 - 好奇心日报荣誉出品 (#2252)

This commit is contained in:
Henry Wang
2019-05-29 03:57:33 +01:00
committed by DIYgod
parent 5dc7b99454
commit b5cfbb7bd2
4 changed files with 137 additions and 4 deletions

View File

@@ -486,25 +486,35 @@ pageClass: routes
<Route author="LogicJake" example="/vocus/user/tsetyan" path="/vocus/user/:id" :paramsDesc="['用户 id可在用户主页的 URL 找到']"/> <Route author="LogicJake" example="/vocus/user/tsetyan" path="/vocus/user/:id" :paramsDesc="['用户 id可在用户主页的 URL 找到']"/>
## 好奇怪
### 首页
<Route author="HenryQW" example="/qdaily/notch/index" path="/qdaily/notch/index" />
### 探索
<Route author="HenryQW" example="/qdaily/notch/explore/1" path="/qdaily/explore/:id" :paramsDesc="['探索 id可通过好奇怪 APP 复制分享链接找到']"/>
## 好奇心日报 ## 好奇心日报
### 分类 ### 分类
<Route author="WenhuWee" example="/qdaily/category/5" path="/qdaily/category/:id" :paramsDesc="['分类id可在分类URL找到']"/> <Route author="WenhuWee" example="/qdaily/category/5" path="/qdaily/category/:id" :paramsDesc="['分类 id可在分类 URL 找到']"/>
### 栏目 ### 栏目
<Route author="WenhuWee emdoe" example="/qdaily/column/59" path="/qdaily/column/:id" :paramsDesc="['栏目id可在栏目URL找到']"/> <Route author="WenhuWee emdoe" example="/qdaily/column/59" path="/qdaily/column/:id" :paramsDesc="['栏目 id可在栏目 URL 找到']"/>
### 标签 ### 标签
<Route author="SivaGao" example="/qdaily/tag/29" path="/qdaily/tag/:id" :paramsDesc="['标签id可在tagURL找到']"/> <Route author="SivaGao" example="/qdaily/tag/29" path="/qdaily/tag/:id" :paramsDesc="['标签 id可在 tag URL 找到']"/>
## 虎扑 ## 虎扑
### 虎扑 BBS 论坛 ### 虎扑 BBS 论坛
<Route author="LogicJake" example="/hupu/bbs/bxj/2" path="/hupu/bbs/:id/:order?" :paramsDesc="['板块id可在板块 URL 找到', '排序方式1最新回帖默认2最新发帖3精华帖']"/> <Route author="LogicJake" example="/hupu/bbs/bxj/2" path="/hupu/bbs/:id/:order?" :paramsDesc="['板块 id可在板块 URL 找到', '排序方式1最新回帖默认2最新发帖3精华帖']"/>
## 即刻 ## 即刻

View File

@@ -212,6 +212,8 @@ router.get('/jiemian/list/:cid', require('./routes/jiemian/list.js'));
router.get('/qdaily/column/:id', require('./routes/qdaily/column')); router.get('/qdaily/column/:id', require('./routes/qdaily/column'));
router.get('/qdaily/category/:id', require('./routes/qdaily/category')); router.get('/qdaily/category/:id', require('./routes/qdaily/category'));
router.get('/qdaily/tag/:id', require('./routes/qdaily/tag')); router.get('/qdaily/tag/:id', require('./routes/qdaily/tag'));
router.get('/qdaily/notch/posts', require('./routes/qdaily/notch/index'));
router.get('/qdaily/notch/explore/:id', require('./routes/qdaily/notch/explore'));
// 爱奇艺 // 爱奇艺
router.get('/iqiyi/dongman/:id', require('./routes/iqiyi/dongman')); router.get('/iqiyi/dongman/:id', require('./routes/iqiyi/dongman'));

View File

@@ -0,0 +1,65 @@
const axios = require('@/utils/axios');
const headers = {
'User-Agent': 'QdailyNotch/3.2.3 (iPhone; iOS 12.3.1; Scale/3.00)',
Host: 'notch.qdaily.com',
};
const ProcessFeed = async (type, item) => {
const processPhoto = (pics) => {
let description = '<div style="text-align: center">';
pics.forEach((pic) => {
description += `<img src='${pic.preview_pic}' referrerpolicy="no-referrer"> <br> <a href='${pic.original_pic.split('?imageMogr2/')[0]}'>下载原图</a> <br> <br>`;
});
description += '</div>';
return description;
};
switch (type) {
case 'lab':
return `<div style="text-align: center"><img src='${item.index_info.index_pic}' referrerpolicy="no-referrer"> <br> ${item.post.description} <br> <a href='${item.post.share.url}'>参与讨论</a></div>`;
case 'long_photo':
return processPhoto(item.long_photos);
case 'photo':
return processPhoto(item.photos);
}
};
module.exports = async (ctx) => {
const meta = await axios({
method: 'get',
url: `http://notch.qdaily.com/api/v3/tags/${ctx.params.id}`,
headers,
});
const data = meta.data.response.tag;
const post = await axios({
method: 'get',
url: `http://notch.qdaily.com/api/v3/tags/post_index?id=${ctx.params.id}`,
headers,
});
const posts = post.data.response.feeds;
const items = await Promise.all(
posts.map(async (item) => {
const post = item.post;
return {
title: post.title,
description: await ProcessFeed(data.index_type, item),
link: post.share.url,
pubDate: new Date(post.published_at).toUTCString(),
author: data.title,
};
})
);
ctx.state.data = {
title: `好奇怪 - ${data.title}`,
link: `http://notch.qdaily.com/`,
description: data.description,
item: items,
};
};

View File

@@ -0,0 +1,56 @@
const axios = require('@/utils/axios');
const cheerio = require('cheerio');
const headers = {
'User-Agent': 'QdailyNotch/3.2.3 (iPhone; iOS 12.3.1; Scale/3.00)',
Host: 'notch.qdaily.com',
};
const ProcessFeed = async (id) => {
const response = await axios({
method: 'get',
url: `http://notch.qdaily.com/api/v3/posts/${id}?platform=ios`,
headers,
});
const $ = cheerio.load(response.data.response.show_info.body);
const description = $('.article-detail-bd');
$('.article-banner > img').insertBefore(description[0].firstChild);
description.find('.lazyload').each((i, e) => {
$(e).attr('src', $(e).attr('data-src'));
});
return description.html();
};
module.exports = async (ctx) => {
const response = await axios({
method: 'get',
url: 'http://notch.qdaily.com/api/v3/posts',
headers,
});
const data = response.data.response.feeds;
const items = await Promise.all(
data.map(async (item) => {
const post = item.post;
return {
title: post.title,
description: await ProcessFeed(post.id),
link: post.share.url,
pubDate: new Date(post.published_at).toUTCString(),
author: post.author_info ? post.author_info.username : '',
};
})
);
ctx.state.data = {
title: `好奇怪 - 首页`,
link: `http://notch.qdaily.com/`,
description: `好奇怪,开启你的脑洞世界。好奇心日报旗下产品。`,
item: items,
};
};