feat: add oak ridge national laboratory news (#6530)

This commit is contained in:
Ethan Shen
2020-12-26 05:55:59 +00:00
committed by GitHub
parent c3d6602694
commit f865de3fdf
4 changed files with 63 additions and 0 deletions
+6
View File
@@ -225,6 +225,12 @@ This route provides a flexible plan with full text content to subscribe specific
</RouteEn>
## Oak Ridge National Laboratory
### News
<RouteEn author="nczitzk" example="/ornl/news" path="/ornl/news"/>
## OpenAI
### Blog
+6
View File
@@ -1897,6 +1897,12 @@ column 为 third 时可选的 category:
</Route>
## 橡树岭国家实验室
### 新闻
<Route author="nczitzk" example="/ornl/news" path="/ornl/news"/>
## 香水时代
### 首页
+3
View File
@@ -3744,6 +3744,9 @@ router.get('/idaily/today', require('./routes/idaily/index'));
// 北屋
router.get('/northhouse/:category?', require('./routes/northhouse/index'));
// Oak Ridge National Laboratory
router.get('/ornl/news', require('./routes/ornl/news'));
// 信阳师范学院 自考办
router.get('/xynu/zkb/:category', require('./routes/universities/xynu/zkb'));
+48
View File
@@ -0,0 +1,48 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://www.ornl.gov';
const currentUrl = `${rootUrl}/news`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.list-item-title h2 a')
.slice(0, 15)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
};
})
.get();
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('article').html();
item.pubDate = new Date(content('time').attr('datetime')).toUTCString();
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};