feat: add leemeng blog (#3068)

This commit is contained in:
凉凉
2019-09-15 12:49:15 +08:00
committed by DIYgod
parent e08fca7794
commit 3f97107dae
3 changed files with 39 additions and 0 deletions

View File

@@ -26,6 +26,12 @@ pageClass: routes
<Route author="kt286" example="/latexstudio/home" path="/latexstudio/home"/>
## LeeMeng
### blog
<Route author="xyqfer" example="/leemeng" path="/leemeng"/>
## 财新博客
### 用户博客

View File

@@ -1717,6 +1717,9 @@ router.get('/engadget-cn', require('./routes/engadget-cn/home'));
// 吹牛部落
router.get('/chuiniu/column/:id', require('./routes/chuiniu/column'));
// leemeng
router.get('/leemeng', require('./routes/blogs/leemeng'));
// 中国地质大学
router.get('/cug/graduate', require('./routes/cug/graduate'));

View File

@@ -0,0 +1,30 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const url = 'https://leemeng.tw/blog.html';
const response = await got({
method: 'get',
url,
});
const $ = cheerio.load(response.data);
const resultItem = $('article')
.map((index, elem) => {
elem = $(elem);
const $link = elem.find('[rel="bookmark"]');
const title = $link.text();
const link = $link.attr('href');
return {
title,
link,
};
})
.get();
ctx.state.data = {
title: 'LeeMeng - 部落格',
link: url,
item: resultItem,
};
};