feat: add Go语言爱好者周刊 (#5039)

This commit is contained in:
Weilet
2020-06-25 23:37:42 +08:00
committed by GitHub
parent 6aa7e0dff0
commit fd0988c99f
3 changed files with 38 additions and 0 deletions

View File

@@ -155,6 +155,12 @@ GitHub 官方也提供了一些 RSS:
</Route> </Route>
## Go语言中文网
### 周刊
<Route author="Weilet" example="/go-weekly" path="/go-weekly"/>
## Hacker News ## Hacker News
### 分类 ### 分类

View File

@@ -2864,4 +2864,7 @@ router.get('/changku', require('./routes/changku/index'));
// 上海市生态环境局 // 上海市生态环境局
router.get('/gov/shanghai/sthj', require('./routes/gov/shanghai/sthj')); router.get('/gov/shanghai/sthj', require('./routes/gov/shanghai/sthj'));
// Go语言爱好者周刊
router.get('/go-weekly', require('./routes/go-weekly'));
module.exports = router; module.exports = router;

View File

@@ -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,
};
};