feat: add oak ridge national laboratory news (#6530)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1897,6 +1897,12 @@ column 为 third 时可选的 category:
|
||||
|
||||
</Route>
|
||||
|
||||
## 橡树岭国家实验室
|
||||
|
||||
### 新闻
|
||||
|
||||
<Route author="nczitzk" example="/ornl/news" path="/ornl/news"/>
|
||||
|
||||
## 香水时代
|
||||
|
||||
### 首页
|
||||
|
||||
@@ -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'));
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user