diff --git a/docs/social-media.md b/docs/social-media.md index 5d684112ea..5429f4881b 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -486,25 +486,35 @@ pageClass: routes +## 好奇怪 + +### 首页 + + + +### 探索 + + + ## 好奇心日报 ### 分类 - + ### 栏目 - + ### 标签 - + ## 虎扑 ### 虎扑 BBS 论坛 - + ## 即刻 diff --git a/lib/router.js b/lib/router.js index df2db46621..a6ffdb5b0a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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/category/:id', require('./routes/qdaily/category')); 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')); diff --git a/lib/routes/qdaily/notch/explore.js b/lib/routes/qdaily/notch/explore.js new file mode 100644 index 0000000000..09d0f6866b --- /dev/null +++ b/lib/routes/qdaily/notch/explore.js @@ -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 = '
'; + pics.forEach((pic) => { + description += `
下载原图

`; + }); + + description += '
'; + return description; + }; + + switch (type) { + case 'lab': + return `

${item.post.description}
参与讨论
`; + 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, + }; +}; diff --git a/lib/routes/qdaily/notch/index.js b/lib/routes/qdaily/notch/index.js new file mode 100644 index 0000000000..443e0cc22b --- /dev/null +++ b/lib/routes/qdaily/notch/index.js @@ -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, + }; +};