feat: add 才府社区用户动态 (#5074)

This commit is contained in:
Ethan Shen
2020-06-28 11:38:42 +08:00
committed by GitHub
parent 40d425988e
commit 22b9c87565
3 changed files with 39 additions and 0 deletions
+6
View File
@@ -168,6 +168,12 @@ pageClass: routes
<Route author="liyefox" example="/v2ex/tab/hot" path="/v2ex/tab/:tabid" :paramsDesc="['tab标签ID,在 URL 可以找到']"/>
## 才符
### 用户动态
<Route author="nczitzk" example="/91ddcc/user/2377095" path="/91ddcc/user/:user" :paramsDesc="['用户ID,在 URL 可以找到']"/>
## 电鸭社区
### 工作机会
+3
View File
@@ -2874,6 +2874,9 @@ router.get('/changku', require('./routes/changku/index'));
// 上海市生态环境局
router.get('/gov/shanghai/sthj', require('./routes/gov/shanghai/sthj'));
// 才符
router.get('/91ddcc/user/:user', require('./routes/91ddcc/user'));
// BookwalkerTW热门新书
router.get('/bookwalkertw/news', require('./routes/bookwalkertw/news'));
+30
View File
@@ -0,0 +1,30 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const currentUrl = `https://sns.91ddcc.com/${ctx.params.user}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('div.dynamic-single')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const word = item.find('div.word');
return {
title: item.find('div.detail-time').text(),
link: `https://sns.91ddcc.com/${item.attr('id').split('-')[1]}`,
description: word.html(),
pubDate: new Date(item.find('div.detail-time').text() + ' GMT+8').toUTCString(),
};
})
.get();
ctx.state.data = {
title: `${$('span.user-name').text()} - 才符`,
link: currentUrl,
item: list,
};
};