From 033ca9b2c16a6cf90a452b73bbd4a4539de26932 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 2 Mar 2021 12:43:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=85=A8=E7=90=83?= =?UTF-8?q?=E5=8C=96=E6=99=BA=E5=BA=93=20(#6975)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: NeverBehave --- docs/new-media.md | 12 ++++++++++ lib/router.js | 3 +++ lib/routes/ccg/index.js | 50 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 lib/routes/ccg/index.js diff --git a/docs/new-media.md b/docs/new-media.md index 8c302c83708e6e..32aa80075d091e 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1668,6 +1668,18 @@ column 为 third 时可选的 category: +## 全球化智库 + +### 分类 + + + +| 新闻动态 | 媒体报道 | 观点 | +| -------- | -------- | ---- | +| news | mtbd | view | + + + ## 全现在 diff --git a/lib/router.js b/lib/router.js index 6d54289241dadf..c2a1b544f214da 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3975,6 +3975,9 @@ router.get('/iyiou', require('./routes/iyiou')); // 香港商报 router.get('/hkcd/pdf', require('./routes/hkcd/pdf')); +// 全球化智库 +router.get('/ccg/:category?', require('./routes/ccg/index')); + // 少女前线 router.get('/gf-cn/news/:category?', require('./routes/gf-cn/news')); diff --git a/lib/routes/ccg/index.js b/lib/routes/ccg/index.js new file mode 100644 index 00000000000000..bcd0a59367f59b --- /dev/null +++ b/lib/routes/ccg/index.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const category = ctx.params.category || 'news'; + + const rootUrl = 'http://www.ccg.org.cn'; + const currentUrl = `${rootUrl}/${category}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.huodong-list li a') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + link: item.attr('href'), + title: item.find('h5').text(), + pubDate: new Date(item.find('span').text().replace(/年|月/g, '-').replace(/日/, '')).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('.pinpai-page').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('title').text()} - 全球化智库`, + link: currentUrl, + item: items, + }; +};