feat: add international energy agency news and events (#6403)
This commit is contained in:
parent
5760b2ee74
commit
dffd55eac5
|
|
@ -140,6 +140,18 @@ Provides a better reading experience (full text articles) over the official one.
|
|||
|
||||
<RouteEn author="nczitzk" example="/iie/blog" path="/iie/blog" />
|
||||
|
||||
## International Energy Agency
|
||||
|
||||
### News and events
|
||||
|
||||
<RouteEn author="nczitzk" example="/iea/news-and-events" path="/iea/:category?" :paramsDesc="['Category, see below, Featured by default']">
|
||||
|
||||
| Featured | News | Calendar | Past events |
|
||||
| --------------- | ---- | -------- | ----------- |
|
||||
| news-and-events | news | calendar | past-events |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## Letterboxd
|
||||
|
||||
### User diary
|
||||
|
|
|
|||
|
|
@ -1015,6 +1015,18 @@ others = 热点新闻 + 滚动新闻
|
|||
|
||||
<Route author="nczitzk" example="/iie/blog" path="/iie/blog" />
|
||||
|
||||
## 国际能源署
|
||||
|
||||
### 新闻及活动
|
||||
|
||||
<Route author="nczitzk" example="/iea/news-and-events" path="/iea/:category?" :paramsDesc="['分类,见下表,默认为 Featured']">
|
||||
|
||||
| Featured | News | Calendar | Past events |
|
||||
| --------------- | ---- | -------- | ----------- |
|
||||
| news-and-events | news | calendar | past-events |
|
||||
|
||||
</Route>
|
||||
|
||||
## 果壳网
|
||||
|
||||
### 科学人
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue