diff --git a/docs/en/new-media.md b/docs/en/new-media.md index 86e1e7d15c..f075489089 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -41,6 +41,18 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more +## Bell Labs + +### Event and News + + + +| Featured events | Latest recognition | Press releases | +| ------- | ---------- | -------- | +| events | industry-recognition | press-releases | + + + ## BOF ### Home diff --git a/docs/new-media.md b/docs/new-media.md index 679acab72b..7350c63472 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -96,6 +96,18 @@ pageClass: routes +## Bell Labs + +### Event and News + + + +| Featured events | Latest recognition | Press releases | +| --------------- | -------------------- | -------------- | +| events | industry-recognition | press-releases | + + + ## BOF ### 首页 diff --git a/lib/router.js b/lib/router.js index 7a3e45a135..3ea716188f 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/bell-labs/events-news.js b/lib/routes/bell-labs/events-news.js new file mode 100644 index 0000000000..25ddf2a7df --- /dev/null +++ b/lib/routes/bell-labs/events-news.js @@ -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' ? `

${$(i).find('p').last().text()}

` : '', + }; + }) + .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, + }; +};