feat: add Institute of International Education blog (#6321)
This commit is contained in:
parent
8284ff95c1
commit
facbd716f4
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -254,6 +254,12 @@ Tag
|
|||
|
||||
</Route>
|
||||
|
||||
## 国际教育研究所
|
||||
|
||||
### Blog
|
||||
|
||||
<Route author="nczitzk" example="/iie/blog" path="/iie/blog" />
|
||||
|
||||
## InfoQ 中文
|
||||
|
||||
### 推荐
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue