Skip to content

Commit

Permalink
WHAT: Refactor
Browse files Browse the repository at this point in the history
WHY:

* XXXXX

HOW:

* NOTHING TO SAY
  • Loading branch information
ecmadao committed Jul 24, 2018
1 parent 6847d89 commit 24881f0
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
# [Hacknical](https://hacknical.com?locale=en)
# [Hacknical](https://hacknical.com)

**hacknical, hacker & technical**

Expand Down
17 changes: 6 additions & 11 deletions app/middlewares/locale.js
Expand Up @@ -3,20 +3,15 @@ import logger from '../utils/logger';
const validateQueryLocale = (locale) => {
const language = locale;
if (!language) return null;
if (/^en/.test(language)) {
return 'en';
}
if (/^fr/.test(language)) {
return 'fr';
}
if (/^zh/.test(language)) {
return 'zh';
}
if (/^en/.test(language)) return 'en';
// if (/^fr/.test(language)) return 'fr';
if (/^zh/.test(language)) return 'zh';
return null;
};

const formatLocale = locale => locale.split(/-|_/)[0];

const checkLocale = () => async (ctx, next) => {
const localeMiddleware = () => async (ctx, next) => {
const queryLocale = validateQueryLocale(ctx.query.locale);
if (queryLocale) {
ctx.session.locale = queryLocale;
Expand All @@ -34,4 +29,4 @@ const checkLocale = () => async (ctx, next) => {
logger.info(`[LOCALE][${ctx.state.locale}]`);
};

export default checkLocale;
export default localeMiddleware;
3 changes: 3 additions & 0 deletions config/localdev.json
Expand Up @@ -5,6 +5,9 @@
"database": {
"redis": "redis://localhost:6379/3"
},
"qiniu": {
"BucketName": "hacknical"
},
"services": {
"github": {
"url": "http://127.0.0.1:5002",
Expand Down
18 changes: 4 additions & 14 deletions frontend/components/GitHub/CodeCourse/index.jsx
Expand Up @@ -21,16 +21,15 @@ const getDateBySeconds = seconds =>
dateHelper.validator.fullDateBySeconds(seconds).split('T')[0];
const formatCommitsTimeline = githubHelper.formatCommitsTimeline();

const yearAgo = dateHelper.date.beforeYears(1);
const maxDateSeconds = getSecondsByDate(getValidateDate());
const minDateSeconds = getSecondsByDate(dateHelper.date.beforeMonths(1, yearAgo));

class CodeCourse extends React.Component {
constructor(props) {
super(props);
const yearAgo = dateHelper.date.beforeYears(1);
const dayOfWeek = dateHelper.date.dayOfWeek(yearAgo);
this.state = {
showedCount: 10,
yearAgoSeconds: getSecondsByDate(yearAgo) - dayOfWeek * SECONDS_PER_DAY,
maxDateSeconds: getSecondsByDate(getValidateDate()),
minDateSeconds: getSecondsByDate(dateHelper.date.beforeMonths(1, yearAgo)),
};
}

Expand Down Expand Up @@ -74,7 +73,6 @@ class CodeCourse extends React.Component {
}

formatRepositories() {
const { minDateSeconds } = this.state;
const { commitDatas } = this.props;
const repositoriesDict = this.repositoriesDict;
const showedCount = Math.min(this.state.showedCount, commitDatas.length);
Expand All @@ -87,7 +85,6 @@ class CodeCourse extends React.Component {
}

renderChosedRepos() {
const { maxDateSeconds, minDateSeconds } = this.state;
const formatRepositories = this.formatRepositories();

return (
Expand All @@ -111,10 +108,6 @@ class CodeCourse extends React.Component {
}

renderTimeLines(repos) {
const {
maxDateSeconds,
minDateSeconds,
} = this.state;
const totalSeconds = maxDateSeconds - minDateSeconds;

return repos.map((repository, index) => {
Expand Down Expand Up @@ -150,9 +143,6 @@ class CodeCourse extends React.Component {
totalSeconds,
} = options;
const timelineDOMs = [<div key={'placeholder'} />];
const {
minDateSeconds,
} = this.state;
let preToSecond = minDateSeconds;
let preCommit = null;

Expand Down
18 changes: 4 additions & 14 deletions frontend/components/Github/CodeCourse/index.jsx
Expand Up @@ -21,16 +21,15 @@ const getDateBySeconds = seconds =>
dateHelper.validator.fullDateBySeconds(seconds).split('T')[0];
const formatCommitsTimeline = githubHelper.formatCommitsTimeline();

const yearAgo = dateHelper.date.beforeYears(1);
const maxDateSeconds = getSecondsByDate(getValidateDate());
const minDateSeconds = getSecondsByDate(dateHelper.date.beforeMonths(1, yearAgo));

class CodeCourse extends React.Component {
constructor(props) {
super(props);
const yearAgo = dateHelper.date.beforeYears(1);
const dayOfWeek = dateHelper.date.dayOfWeek(yearAgo);
this.state = {
showedCount: 10,
yearAgoSeconds: getSecondsByDate(yearAgo) - dayOfWeek * SECONDS_PER_DAY,
maxDateSeconds: getSecondsByDate(getValidateDate()),
minDateSeconds: getSecondsByDate(dateHelper.date.beforeMonths(1, yearAgo)),
};
}

Expand Down Expand Up @@ -74,7 +73,6 @@ class CodeCourse extends React.Component {
}

formatRepositories() {
const { minDateSeconds } = this.state;
const { commitDatas } = this.props;
const repositoriesDict = this.repositoriesDict;
const showedCount = Math.min(this.state.showedCount, commitDatas.length);
Expand All @@ -87,7 +85,6 @@ class CodeCourse extends React.Component {
}

renderChosedRepos() {
const { maxDateSeconds, minDateSeconds } = this.state;
const formatRepositories = this.formatRepositories();

return (
Expand All @@ -111,10 +108,6 @@ class CodeCourse extends React.Component {
}

renderTimeLines(repos) {
const {
maxDateSeconds,
minDateSeconds,
} = this.state;
const totalSeconds = maxDateSeconds - minDateSeconds;

return repos.map((repository, index) => {
Expand Down Expand Up @@ -150,9 +143,6 @@ class CodeCourse extends React.Component {
totalSeconds,
} = options;
const timelineDOMs = [<div key={'placeholder'} />];
const {
minDateSeconds,
} = this.state;
let preToSecond = minDateSeconds;
let preCommit = null;

Expand Down
4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -149,7 +149,6 @@
"cache-manager": "^2.9.0",
"co-redis": "^2.1.1",
"config": "^1.21.0",
"eventemitter3": "^3.0.1",
"font-awesome": "^4.7.0",
"fs-extra": "^2.0.0",
"hiredis": "^0.5.0",
Expand All @@ -172,8 +171,7 @@
"phantom": "^4.0.1",
"redis": "^2.6.3",
"request": "^2.75.0",
"rsmq": "^0.8.2",
"shortid": "^2.2.8"
"rsmq": "^0.8.2"
},
"repository": {
"url": "git@github.com:ecmadao/hacknical.git",
Expand Down
4 changes: 2 additions & 2 deletions scripts/deploy/cdn/index.js
Expand Up @@ -8,8 +8,8 @@ const BucketName = config.get('qiniu.BucketName');
const AccessKey = config.get('qiniu.AccessKey');
const SecretKey = config.get('qiniu.SecretKey');

qiniu.conf.ACCESS_KEY = AccessKey;
qiniu.conf.SECRET_KEY = SecretKey;
qiniu.conf.ACCESS_KEY = AccessKey || process.env.QINIU_ACCESS_KEY;
qiniu.conf.SECRET_KEY = SecretKey || process.env.QINIU_SECRET_KEY;

const getFiles = () => {
const files = klawSync(PATH.PUBLIC_PATH, { nodir: true })
Expand Down

0 comments on commit 24881f0

Please sign in to comment.