diff --git a/docs/en/new-media.md b/docs/en/new-media.md index 35fce6e6b..a2862e49c 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -140,6 +140,18 @@ Provides a better reading experience (full text articles) over the official one. +## International Energy Agency + +### News and events + + + +| Featured | News | Calendar | Past events | +| --------------- | ---- | -------- | ----------- | +| news-and-events | news | calendar | past-events | + + + ## Letterboxd ### User diary diff --git a/docs/new-media.md b/docs/new-media.md index 6eb0769d7..4e0129d9e 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1015,6 +1015,18 @@ others = 热点新闻 + 滚动新闻 +## 国际能源署 + +### 新闻及活动 + + + +| Featured | News | Calendar | Past events | +| --------------- | ---- | -------- | ----------- | +| news-and-events | news | calendar | past-events | + + + ## 果壳网 ### 科学人 diff --git a/lib/router.js b/lib/router.js index 0c3bc7a40..06e3afbaa 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3677,6 +3677,9 @@ router.get('/cool18/:id?/:type?/:keyword?', require('./routes/cool18/index')); // 美国贸易代表办公室 router.get('/ustr/press-releases/:year?/:month?', require('./routes/us/ustr/press-releases')); +// 国际能源署 +router.get('/iea/:category?', require('./routes/iea/index')); + // 中国计算机学会 router.get('/ccf/news/:category?', require('./routes/ccf/news')); diff --git a/lib/routes/iea/index.js b/lib/routes/iea/index.js new file mode 100644 index 000000000..aa5dffe0d --- /dev/null +++ b/lib/routes/iea/index.js @@ -0,0 +1,54 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const category = ctx.params.category || 'news-and-events'; + + const rootUrl = 'https://www.iea.org'; + const currentUrl = `${rootUrl}/${category}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.m-news-listing__hover') + .slice(0, 15) + .map((_, item) => { + item = $(item); + + const title = $(item).text(); + item = item.parent().get(0).tagName === 'a' ? $(item).parent() : $(item).parent().parent(); + + return { + title, + 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('.m-block__content').html(); + item.pubDate = new Date(content('.o-hero-freepage__meta').text()).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').eq(0).text(), + link: currentUrl, + item: items, + }; +};