From c7fbc389f056aaff2eb15d8382dfbbb97268ec5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=89=E5=87=89?= Date: Wed, 7 Nov 2018 21:17:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0:=20GitChat=20(#1088)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 日常翻车系列 🌚 --- docs/README.md | 6 ++++++ router.js | 3 +++ routes/gitchat/newest.js | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 routes/gitchat/newest.js diff --git a/docs/README.md b/docs/README.md index 163f19fd6..968b38962 100644 --- a/docs/README.md +++ b/docs/README.md @@ -736,6 +736,12 @@ GitHub 官方也提供了一些 RSS: +### GitChat + + + +> GitChat 需要付费订阅, RSS 仅做更新提醒, 不含付费内容. + ## 直播 ### 哔哩哔哩直播 diff --git a/router.js b/router.js index fff220d71..401304f88 100644 --- a/router.js +++ b/router.js @@ -770,4 +770,7 @@ router.get('/itjuzi/merge', require('./routes/itjuzi/merge')); // 探物 router.get('/tanwu/products', require('./routes/tanwu/products')); +// GitChat +router.get('/gitchat/newest', require('./routes/gitchat/newest')); + module.exports = router; diff --git a/routes/gitchat/newest.js b/routes/gitchat/newest.js new file mode 100644 index 000000000..6c469e4cd --- /dev/null +++ b/routes/gitchat/newest.js @@ -0,0 +1,38 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const response = await axios({ + method: 'get', + 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 { + title: item.find('.chat_info_title').text(), + description: + `作者: ${author}

` + + item + .find('.chat_info_desc') + .text() + .replace(/\n/g, '
'), + link: `https://gitbook.cn${item + .find('a') + .eq(0) + .attr('href')}`, + author, + }; + }) + .get(); + + ctx.state.data = { + title: 'GitChat-最新', + link: 'https://gitbook.cn/gitchat/news', + description: 'GitChat 是一款基于微信平台的知识分享产品。通过这款产品我们希望改变IT知识的学习方式。', + item: resultItem, + }; +};