diff --git a/docs/new-media.md b/docs/new-media.md index 4e0129d9e..aaed639be 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1934,6 +1934,18 @@ column 为 third 时可选的 category: +## 中国机械工程学会 + +### 学会新闻 + + + +| 学会要闻 | 学会动态 | 科技新闻 | +| ----------- | -------- | -------- | +| Information | Dynamics | TechNews | + + + ## 中国劳工观察 ### 调查报告 diff --git a/lib/router.js b/lib/router.js index 84212d575..e2c515fe9 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3698,4 +3698,7 @@ router.get('/treasury/press-releases/:category?/:title?', require('./routes/us/t // Bandisoft router.get('/bandisoft/:id?/:lang?', require('./routes/bandisoft/index')); +// 中国机械工程学会 +router.get('/cmes/news/:category?', require('./routes/cmes/news')); + module.exports = router; diff --git a/lib/routes/cmes/news.js b/lib/routes/cmes/news.js new file mode 100644 index 000000000..9abf15bc3 --- /dev/null +++ b/lib/routes/cmes/news.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const category = ctx.params.category || 'Information'; + + const rootUrl = 'https://www.cmes.org'; + const currentUrl = `${rootUrl}/News/${category}/index.html`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.r_ct') + .find('a') + .slice(0, 10) + .map((_, item) => { + item = $(item); + + const link = item.attr('href'); + + let date = '00000000'; + if (link.split('/')[2] !== 'mkc.ckcest.cn') { + date = link.split('/')[5]; + } + + return { + link, + title: item.text(), + pubDate: new Date(`${date.substr(0, 4)}-${date.substr(5, 2)}-${date.substr(7, 2)}`).toDateString(), + }; + }) + .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); + + content('h3, script, .bshare-custom').remove(); + + item.description = content('.xhjj').html() || content('.detail-page').html(); + + if (content('#articleTime').html()) { + item.pubDate = new Date(content('#articleTime').text()).toUTCString(); + } + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};