Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add dbaplus社群活动 #7584

Merged
merged 2 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pageClass: routes

## dbaplus 社群

### 栏目

<Route author="nczitzk" example="/dbaplus" path="/dbaplus/:tab?" :paramsDesc="['栏目,见下表,默认为全部']">

| 全部 | 数据库 | 运维 | 大数据 | 架构 | PaaS 云 | 职场生涯 | 这里有毒 |
Expand All @@ -40,6 +42,16 @@ pageClass: routes

</Route>

### 活动

<Route author="nczitzk" example="/dbaplus/activity" path="/dbaplus/activity/:type?" :paramsDesc="['分类,见下表,默认为线上分享']">

| 线上分享 | 线下峰会 |
| -------- | -------- |
| online | offline |

</Route>

## deeplearning.ai

### TheBatch 周报
Expand Down
1 change: 1 addition & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4057,6 +4057,7 @@ router.get('/wainao-reads/all-articles', require('./routes/wainao/index'));
router.get('/react/react-native-weekly', require('./routes/react/react-native-weekly'));

// dbaplus 社群
router.get('/dbaplus/activity/:type?', require('./routes/dbaplus/activity.js'));
router.get('/dbaplus/:tab?', require('./routes/dbaplus/tab'));

// 梨园
Expand Down
35 changes: 35 additions & 0 deletions lib/routes/dbaplus/activity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const type = ctx.params.type || 'online';

const rootUrl = 'https://dbaplus.cn';
const currentUrl = `${rootUrl}/activity-${type === 'online' ? '12' : '48'}-1.html`;
const response = await got({
method: 'get',
url: currentUrl,
});

const $ = cheerio.load(response.data);

const items = $('.media')
.map((_, item) => {
item = $(item);

return {
title: item.find('.media-heading').text(),
link: item.find('.pull-left').attr('href'),
description: `<img src="${item.find('.media-object').attr('src')}">`,
pubDate: timezone(new Date(item.find('.time').text().replace('时间:', '')), +8),
};
})
.get();

ctx.state.data = {
title: $('title').text().split(':')[0],
link: currentUrl,
item: items,
};
};