From fd0988c99fdab8f0888ee50cee7028fed5cf7945 Mon Sep 17 00:00:00 2001 From: Weilet <32561597+Weilet@users.noreply.github.com> Date: Thu, 25 Jun 2020 23:37:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20Go=E8=AF=AD=E8=A8=80=E7=88=B1?= =?UTF-8?q?=E5=A5=BD=E8=80=85=E5=91=A8=E5=88=8A=20(#5039)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/programming.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/go-weekly/index.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 lib/routes/go-weekly/index.js diff --git a/docs/programming.md b/docs/programming.md index f3a85ee509..5466d9badb 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -155,6 +155,12 @@ GitHub 官方也提供了一些 RSS: +## Go语言中文网 + +### 周刊 + + + ## Hacker News ### 分类 diff --git a/lib/router.js b/lib/router.js index 9615903d60..ae1697e2d4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2864,4 +2864,7 @@ router.get('/changku', require('./routes/changku/index')); // 上海市生态环境局 router.get('/gov/shanghai/sthj', require('./routes/gov/shanghai/sthj')); +// Go语言爱好者周刊 +router.get('/go-weekly', require('./routes/go-weekly')); + module.exports = router; diff --git a/lib/routes/go-weekly/index.js b/lib/routes/go-weekly/index.js new file mode 100644 index 0000000000..38e32f23ee --- /dev/null +++ b/lib/routes/go-weekly/index.js @@ -0,0 +1,29 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const url = 'https://studygolang.com/go/weekly'; + const response = await got({ + method: 'get', + url, + }); + const $ = cheerio.load(response.data); + const resultItem = $('.title') + .map((index, elem) => { + elem = $(elem); + const $link = elem.find('a'); + const title = $link.text(); + const link = $link.attr('href'); + return { + title, + link, + }; + }) + .get(); + + ctx.state.data = { + title: 'Go语言爱好者周刊', + link: url, + item: resultItem, + }; +};