feat(route): add 全球化智库 (#6975)

Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
Ethan Shen
2021-03-01 23:43:13 -05:00
committed by GitHub
co-authored by NeverBehave
parent 11f717906f
commit 033ca9b2c1
3 changed files with 65 additions and 0 deletions
+12
View File
@@ -1668,6 +1668,18 @@ column 为 third 时可选的 category:
</Route>
## 全球化智库
### 分类
<Route author="nczitzk" example="/ccg" path="/ccg/:category?" :paramsDesc="['分类,见下表']">
| 新闻动态 | 媒体报道 | 观点 |
| -------- | -------- | ---- |
| news | mtbd | view |
</Route>
## 全现在
<Route author="nczitzk" example="/allnow/column/199" path="/allnow/column/:id" :paramsDesc="['专栏 id']"/>
+3
View File
@@ -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'));
+50
View File
@@ -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,
};
};