feat: add 得到新闻 & 人物故事 & 视频 (#6119)
This commit is contained in:
@@ -633,6 +633,18 @@ Supported sub-sites:
|
||||
|
||||
## 得到
|
||||
|
||||
### 新闻
|
||||
|
||||
<Route author="nczitzk" example="/dedao/news" path="/dedao/news"/>
|
||||
|
||||
### 人物故事
|
||||
|
||||
<Route author="nczitzk" example="/dedao/figure" path="/dedao/figure"/>
|
||||
|
||||
### 视频
|
||||
|
||||
<Route author="nczitzk" example="/dedao/video" path="/dedao/video"/>
|
||||
|
||||
### 知识城邦
|
||||
|
||||
<Route author="nczitzk" example="/dedao/knowledge" path="/dedao/knowledge/:topic?/:type?" :paramsDesc="['话题 id,可在话题页 URL 中找到', '分享类型,`true` 指精选,`false` 指最新,默认为精选']"/>
|
||||
|
||||
@@ -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'));
|
||||
|
||||
// 未名新闻
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user