feat: add Institute of International Education blog (#6321)

This commit is contained in:
Ethan Shen 2020-12-07 02:03:37 +08:00 committed by GitHub
parent 8284ff95c1
commit facbd716f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 0 deletions

View File

@ -117,6 +117,12 @@ Provides a better reading experience (full text articles) over the official one.
</RouteEn>
## Institute of International Education
### Blog
<RouteEn author="nczitzk" example="/iie/blog" path="/iie/blog" />
## Letterboxd
### User diary

View File

@ -254,6 +254,12 @@ Tag
</Route>
## 国际教育研究所
### Blog
<Route author="nczitzk" example="/iie/blog" path="/iie/blog" />
## InfoQ 中文
### 推荐

View File

@ -3517,6 +3517,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news'));
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
// 国际教育研究所
router.get('/iie/blog', require('./routes/iie/blog'));
// McKinsey Greater China
router.get('/mckinsey/:category?', require('./routes/mckinsey/index'));

48
lib/routes/iie/blog.js Normal file
View File

@ -0,0 +1,48 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://www.iie.org';
const currentUrl = `${rootUrl}/Learn/Blog`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.events__title a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
pubDate: new Date(item.parent().parent().find('time').attr('datetime')).toUTCString(),
};
})
.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('.wysiwyg').html();
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};