fix: gitchat new revision (#3941)

This commit is contained in:
hoilc
2020-02-09 19:50:14 +08:00
committed by GitHub
parent cae4bb2e55
commit 97a008df85
3 changed files with 31 additions and 36 deletions

View File

@@ -26,9 +26,21 @@ pageClass: routes
## GitChat ## GitChat
### 最新 ### 最新文章
<Route author="xyqfer" example="/gitchat/newest" path="/gitchat/newest"/> <Route author="hoilc" example="/gitchat/newest" path="/gitchat/newest/:category?/:selected?" :paramsDesc="['分类 ID, 置空或`all`代表全部, 具体值需要抓取前端请求, 以下列出可能有变动, 仅供参考','是否只显示严选文章, 任意值为是, 置空为否']" />
| 分类名 | 分类 ID |
| :------- | :----------------------- |
| 前端 | 58e84f875295227534aad506 |
| 后端 | 5d8b7c3786194a1921979122 |
| 移动开发 | 5d8b7c3786194a1921979123 |
| 运维 | 5901bd477b61a76bc4016423 |
| 测试 | 58e84f425295227534aad502 |
| 架构 | 58e84f6bad952d6b3428af9a |
| 人工智能 | 58e84f53ec8e9e7b34457809 |
| 职场 | 58e84f1584c651693437f27c |
| 互联网 | 5d8b7c3786194a1921979124 |
> GitChat 需要付费订阅, RSS 仅做更新提醒, 不含付费内容. > GitChat 需要付费订阅, RSS 仅做更新提醒, 不含付费内容.
@@ -268,9 +280,7 @@ GitHub 官方也提供了一些 RSS:
### Scala Blog ### Scala Blog
<Route author="fengkx" example="/scala/blog/posts" path="/scala/blog/:part?" :paramsDesc="['部分']" > <Route author="fengkx" example="/scala/blog/posts" path="/scala/blog/:part?" :paramsDesc="['部分, 默认为All, part参数可在url中获得']" />
默认为All part参数可在url中获得
</Route>
## segmentfault ## segmentfault

View File

@@ -925,7 +925,7 @@ router.get('/itjuzi/merge', require('./routes/itjuzi/merge'));
router.get('/tanwu/products', require('./routes/tanwu/products')); router.get('/tanwu/products', require('./routes/tanwu/products'));
// GitChat // GitChat
router.get('/gitchat/newest', require('./routes/gitchat/newest')); router.get('/gitchat/newest/:category?/:selected?', require('./routes/gitchat/newest'));
// The Guardian // The Guardian
router.get('/guardian/:type', require('./routes/guardian/guardian')); router.get('/guardian/:type', require('./routes/guardian/guardian'));

View File

@@ -1,38 +1,23 @@
const got = require('@/utils/got'); const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => { module.exports = async (ctx) => {
const response = await got({ const category = ctx.params.category && ctx.params.category !== 'all' ? ctx.params.category : '';
method: 'get', const selected = ctx.params.selected;
url: 'https://gitbook.cn/gitchat/news/0/20?searchKey=',
});
const $ = cheerio.load(response.data.data);
const resultItem = $('.col-md-12')
.map((index, item) => {
item = $(item);
const author = item.find('.chat_info_author').text();
return { const response = await got(`https://gitbook.cn/activities?page=1&type=new&isSelected=${selected ? 'true' : 'false'}${category ? '&category=' + category : ''}`);
title: item.find('.chat_info_title').text(), const list = response.data.data;
description:
`作者: ${author}<br><br>` + const category_name = category ? list[0].category.categoryName : '';
item
.find('.chat_info_desc')
.text()
.replace(/\n/g, '<br>'),
link: `https://gitbook.cn${item
.find('a')
.eq(0)
.attr('href')}`,
author,
};
})
.get();
ctx.state.data = { ctx.state.data = {
title: 'GitChat-最新', title: `GitChat ${category ? category_name + ' ' : ''}最新${selected ? '严选' : ''}`,
link: 'https://gitbook.cn/gitchat/news', link: 'https://gitbook.cn/',
description: 'GitChat 是一款基于微信平台的知识分享产品。通过这款产品我们希望改变IT知识的学习方式。', item: list.map((item) => ({
item: resultItem, title: item.title,
author: item.authorId.customerName,
description: `<p>${item.description}</p>`,
pubDate: new Date(),
link: `https://gitbook.cn/gitchat/activity/${item._id}`,
})),
}; };
}; };