Skip to content

Commit

Permalink
feat(route): add 全球化智库 (DIYgod#6975)
Browse files Browse the repository at this point in the history
Co-authored-by: NeverBehave <[email protected]>
  • Loading branch information
Ethan Shen and NeverBehave authored Mar 2, 2021
1 parent 11f7179 commit 033ca9b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']"/>
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
50 changes: 50 additions & 0 deletions lib/routes/ccg/index.js
Original file line number Diff line number Diff line change
@@ -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,
};
};

0 comments on commit 033ca9b

Please sign in to comment.