From facbd716f4b94b75aaca258507a296ccab1c8fcd Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Mon, 7 Dec 2020 02:03:37 +0800 Subject: [PATCH] feat: add Institute of International Education blog (#6321) --- docs/en/new-media.md | 6 ++++++ docs/new-media.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/iie/blog.js | 48 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 lib/routes/iie/blog.js diff --git a/docs/en/new-media.md b/docs/en/new-media.md index 1a347a5e5..2fbee2e6d 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -117,6 +117,12 @@ Provides a better reading experience (full text articles) over the official one. +## Institute of International Education + +### Blog + + + ## Letterboxd ### User diary diff --git a/docs/new-media.md b/docs/new-media.md index e59baa338..bd0a5884b 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -254,6 +254,12 @@ Tag +## 国际教育研究所 + +### Blog + + + ## InfoQ 中文 ### 推荐 diff --git a/lib/router.js b/lib/router.js index ec92e8662..19a76f4a6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/iie/blog.js b/lib/routes/iie/blog.js new file mode 100644 index 000000000..7b26d2105 --- /dev/null +++ b/lib/routes/iie/blog.js @@ -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, + }; +};