feat: add bell labs events news (#6529)

This commit is contained in:
Ethan Shen
2020-12-26 13:52:52 +08:00
committed by GitHub
parent 2fcf82a89c
commit f7a1105798
4 changed files with 98 additions and 0 deletions

View File

@@ -41,6 +41,18 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more
<RouteEn author="nczitzk" example="/asml/press-releases" path="/asml/press-releases"/>
## Bell Labs
### Event and News
<RouteEn author="nczitzk" example="/bell-labs/events-news" path="/bell-labs/events-news/:category?" :paramsDesc="['Category, see below, Press releases by default']">
| Featured events | Latest recognition | Press releases |
| ------- | ---------- | -------- |
| events | industry-recognition | press-releases |
</Route>
## BOF
### Home

View File

@@ -96,6 +96,18 @@ pageClass: routes
<Route author="nczitzk" example="/asml/press-releases" path="/asml/press-releases"/>
## Bell Labs
### Event and News
<Route author="nczitzk" example="/bell-labs/events-news" path="/bell-labs/events-news/:category?" :paramsDesc="['分类,见下表,默认为 Press releases']">
| Featured events | Latest recognition | Press releases |
| --------------- | -------------------- | -------------- |
| events | industry-recognition | press-releases |
</Route>
## BOF
### 首页

View File

@@ -3744,6 +3744,9 @@ router.get('/idaily/today', require('./routes/idaily/index'));
// 北屋
router.get('/northhouse/:category?', require('./routes/northhouse/index'));
// Bell Labs
router.get('/bell-labs/events-news/:category?', require('./routes/bell-labs/events-news.js'));
// 中国科学院青年创新促进会
router.get('/yicas/blog', require('./routes/yicas/blog'));

View File

@@ -0,0 +1,71 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const config = {
events: '.tout-text a',
'industry-recognition': '.n-block-section .n-block .rich-text p b',
'press-releases': 'h5 a',
};
module.exports = async (ctx) => {
const category = ctx.params.category || 'press-releases';
const rootUrl = 'http://www.bell-labs.com';
const currentUrl = `${rootUrl}/events-news/${category}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
let items = (category === 'industry-recognition' ? $(config[category]).closest('.rich-text') : $(config[category]))
.slice(0, 15)
.map((_, i) => {
let item = $(i);
if (category === 'industry-recognition') {
item = item.children('.n-link-list').length > 0 ? item.children('.n-link-list') : item.children('p').eq(1);
}
if (item.children('a').attr('href')) {
item = item.children('a');
}
return {
title: item.text(),
link: item.attr('href') || currentUrl,
pubDate: new Date(category === 'events' ? item.text().split(':')[0].split(' - ')[0] : category === 'industry-recognition' ? $(i).children('p').eq(0).text() : '').toUTCString(),
description: category === 'events' ? item.closest('.n-block').next().find('.rich-text').html() : category === 'industry-recognition' ? `<p>${$(i).find('p').last().text()}</p>` : '',
};
})
.get();
if (category === 'press-releases') {
items = await Promise.all(
items.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);
content('.social-media-sharing').remove();
item.description = content('.layout-content').html();
item.pubDate = new Date(content('meta[name="search-updated"]').attr('content')).toUTCString();
return item;
})
)
);
}
ctx.state.data = {
title: $('title').eq(0).text(),
link: currentUrl,
item: items,
};
};