diff --git a/docs/new-media.md b/docs/new-media.md index 8a0a529df2..2494b6c343 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -375,6 +375,16 @@ pageClass: routes +### 其他栏目 + + + +| 快讯 | 文章 | 活动 | 评测 | 视频 | 访谈 | +| -------------------- | -------------------- | -------------------- | -------------------- | ------------------ | ------------------ | +| type_id=2,tagid 不填 | type_id=1,tagid 不填 | type_id=7,tagid 不填 | type_id=8,tagid 不填 | type_id=1,tagid=70 | type_id=1,tagid=73 | + + + ## 巨潮资讯 ### 公司公告 diff --git a/lib/router.js b/lib/router.js index aa0a86faec..ca0f7722f9 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1089,6 +1089,7 @@ router.get('/wenku8/chapter/:id', require('./routes/wenku8/chapter')); // 鲸跃汽车 router.get('/whalegogo/home', require('./routes/whalegogo/home')); +router.get('/whalegogo/portal/:type_id/:tagid?/', require('./routes/whalegogo/portal')); // 爱思想 router.get('/aisixiang/column/:id', require('./routes/aisixiang/column')); diff --git a/lib/routes/whalegogo/portal.js b/lib/routes/whalegogo/portal.js new file mode 100644 index 0000000000..c846da150a --- /dev/null +++ b/lib/routes/whalegogo/portal.js @@ -0,0 +1,57 @@ +const got = require('@/utils/got'); +module.exports = async (ctx) => { + const type_id = ctx.params.type_id || '2'; + const tagid = ctx.params.tagid || ''; + const sort = ctx.params.sort || '-push_at'; + const url = `https://www.whalegogo.com/list/portal-${type_id}?tag_id=all`; + // type_id = 2:快讯 / 1:文章 / 7:活动 / 8:评测 + // tagid = 70:视频 /73:访谈 + // sort = -push_at 最新 / hot最热 + const response = await got({ + method: 'get', + url: `https://api.whalegogo.com/v1/articles/search?tagid=${tagid}&type_id=${type_id}&sort=${sort}&page=1&per-page=12`, + headers: { + Referer: url, + }, + }); + const list = response.data.items; + const out = await Promise.all( + list.map(async (info) => { + const title = info.title; + const date = info.push_at; + const id = info.id; + // const cid = info.cid; + const author = info.author.username; + const itemUrl = `https://www.whalegogo.com/news?id=${id}`; + const cache = await ctx.cache.get(itemUrl); + // console.log(cid); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const response = await got({ + method: 'get', + url: `https://api.whalegogo.com/v1/articles/${id}?expand=content`, + headers: { + Referer: url, + }, + }); + const description = response.data.content; + + const single = { + title: title, + author, + link: itemUrl, + description: description, + pubDate: new Date(date * 1000).toUTCString(), + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: '鲸跃汽车', + link: url, + item: out, + }; +};