feat: add 光谷社区 (#5086)

This commit is contained in:
Ethan Shen 2020-07-02 12:14:53 +08:00 committed by GitHub
parent 7317061548
commit 8e772c5fa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 101 additions and 6 deletions

View File

@ -180,6 +180,18 @@ pageClass: routes
<Route author="sfyumi" example="/eleduck/jobs" path="/eleduck/jobs"/>
## 光谷社区
### 子论坛
<Route author="nczitzk" example="/guanggoo/index" path="/guanggoo/:caty" :paramsDesc="['子论坛']">
| 首页 | 你问我答 | 同城活动 | IT 技术 | 金融财经 | 创业创客 | 城市建设 |
| ----- | -------- | -------- | ------- | -------- | -------- | -------- |
| index | qna | lowshine | it | finance | startup | city |
</Route>
## 虎扑
### 虎扑 BBS 论坛

View File

@ -248,6 +248,12 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
| ------ | ---- | -------- |
| update | hot | spent |
## 二柄 APP
### 新闻
<Route author="wushijishan" example="/erbingapp/news" path="/erbingapp/news"/>
## 公主链接
### 日服公告
@ -461,9 +467,3 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
### 游戏横幅
<Route author="y2361547758" example="/magireco/event_banner" path="/magireco/event_banner"/>
## 二柄APP
### 新闻
<Route author="wushijishan" example="/erbingapp/news" path="/erbingapp/news"/>

View File

@ -2902,4 +2902,7 @@ router.get('/erbingapp/news', require('./routes/erbingapp/news'));
// 电商报
router.get('/dsb/area/:area', require('./routes/dsb/area'));
// 光谷社区
router.get('/guanggoo/:caty', require('./routes/guanggoo/index'));
module.exports = router;

View File

@ -0,0 +1,80 @@
const url = require('url');
const got = require('@/utils/got');
const cheerio = require('cheerio');
const rootUrl = 'http://www.guanggoo.com/';
const config = {
index: {
link: '',
title: '首页',
},
qna: {
link: '/node/qna',
title: '你问我答',
},
lowshine: {
link: '/node/lowshine',
title: '同城活动',
},
it: {
link: '/node/IT',
title: 'IT技术',
},
finance: {
link: '/node/finance',
title: '金融财经',
},
startup: {
link: '/node/startup',
title: '创业创客',
},
city: {
link: '/node/city',
title: '城市建设',
},
};
module.exports = async (ctx) => {
const cfg = config[ctx.params.caty];
if (!cfg) {
throw Error('Bad category. See <a href="https://docs.rsshub.app/bbs.html#guang-gu-she-qu-zi-lun-tan">docs</a>');
}
const currentUrl = url.resolve(rootUrl, cfg.link);
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('div.topic-item h3 a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: url.resolve(rootUrl, item.attr('href')),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const res = await got({ method: 'get', url: item.link });
const content = cheerio.load(res.data);
item.description = content('div.sidebar-left').html();
return item;
})
)
);
ctx.state.data = {
title: '光谷社区 - ' + cfg.title,
link: rootUrl,
item: items,
};
};