From f865de3fdf5138e491b20de731ab3def5118fc0d Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 26 Dec 2020 13:55:59 +0800 Subject: [PATCH] feat: add oak ridge national laboratory news (#6530) --- docs/en/new-media.md | 6 ++++++ docs/new-media.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/ornl/news.js | 48 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 lib/routes/ornl/news.js diff --git a/docs/en/new-media.md b/docs/en/new-media.md index f07548908..4c88a78f7 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -225,6 +225,12 @@ This route provides a flexible plan with full text content to subscribe specific +## Oak Ridge National Laboratory + +### News + + + ## OpenAI ### Blog diff --git a/docs/new-media.md b/docs/new-media.md index 7350c6347..52a9128e2 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1897,6 +1897,12 @@ column 为 third 时可选的 category: +## 橡树岭国家实验室 + +### 新闻 + + + ## 香水时代 ### 首页 diff --git a/lib/router.js b/lib/router.js index bb341efb7..26bc4126f 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')); +// Oak Ridge National Laboratory +router.get('/ornl/news', require('./routes/ornl/news')); + // 信阳师范学院 自考办 router.get('/xynu/zkb/:category', require('./routes/universities/xynu/zkb')); diff --git a/lib/routes/ornl/news.js b/lib/routes/ornl/news.js new file mode 100644 index 000000000..de07ed137 --- /dev/null +++ b/lib/routes/ornl/news.js @@ -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, + }; +};