diff --git a/docs/new-media.md b/docs/new-media.md index 1a6db7f44..f0105be4d 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -633,6 +633,18 @@ Supported sub-sites: ## 得到 +### 新闻 + + + +### 人物故事 + + + +### 视频 + + + ### 知识城邦 diff --git a/lib/router.js b/lib/router.js index 868569d66..954217658 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3472,6 +3472,7 @@ router.get('/grandchallenge/challenges', require('./routes/grandchallenge/challe router.get('/nwpu/:column', require('./routes/nwpu/index')); // 得到 +router.get('/dedao/:caty?', require('./routes/dedao/index')); router.get('/dedao/knowledge/:topic?/:type?', require('./routes/dedao/knowledge')); // 未名新闻 diff --git a/lib/routes/dedao/index.js b/lib/routes/dedao/index.js new file mode 100644 index 000000000..d7a73158c --- /dev/null +++ b/lib/routes/dedao/index.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const caty = ctx.params.caty || 'news'; + const rootUrl = `https://www.igetget.com/${caty === 'video' ? 'video' : 'news'}`; + + const response = await got({ + method: 'get', + url: rootUrl, + }); + + const data = JSON.parse(response.data.match(/window.__INITIAL_STATE__= (.*);<\/script>/)[1]); + + const list = (caty === 'news' ? data.news : caty === 'figure' ? data.figure : data.videoList).map((item) => ({ + title: item.title, + pubDate: new Date(item.online_time).toUTCString(), + link: `${rootUrl}/${caty === 'news' ? 'article/' : caty === 'figure' ? 'people/' : ''}${item.online_time.split('T')[0].split('-').join('')}/${item.token}`, + })); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('.menu-article').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `得到${caty === 'video' ? '' : '大事件'} - ${caty === 'news' ? '新闻' : caty === 'figure' ? '人物故事' : '视频'}`, + link: rootUrl, + item: items, + description: data.description, + }; +};