Fix(lint): Add import eslint and fix import errors
This commit is contained in:
26
.eslintrc
26
.eslintrc
@ -13,8 +13,19 @@
|
|||||||
},
|
},
|
||||||
"parser": "babel-eslint",
|
"parser": "babel-eslint",
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"react"
|
"react",
|
||||||
|
"import"
|
||||||
],
|
],
|
||||||
|
"settings": {
|
||||||
|
"import/ignore": [
|
||||||
|
"node_modules",
|
||||||
|
"\\.json$"
|
||||||
|
],
|
||||||
|
"import/extensions": [
|
||||||
|
".js",
|
||||||
|
".jsx"
|
||||||
|
]
|
||||||
|
},
|
||||||
"globals": {
|
"globals": {
|
||||||
"Promise": true,
|
"Promise": true,
|
||||||
"window": true,
|
"window": true,
|
||||||
@ -223,9 +234,9 @@
|
|||||||
"no-bitwise": 2,
|
"no-bitwise": 2,
|
||||||
"no-plusplus": 0,
|
"no-plusplus": 0,
|
||||||
|
|
||||||
|
"jsx-quotes": [2, "prefer-single"],
|
||||||
"react/display-name": 2,
|
"react/display-name": 2,
|
||||||
"react/jsx-boolean-value": [2, "always"],
|
"react/jsx-boolean-value": [2, "always"],
|
||||||
"jsx-quotes": [2, "prefer-single"],
|
|
||||||
"react/jsx-no-undef": 2,
|
"react/jsx-no-undef": 2,
|
||||||
"react/jsx-sort-props": [2, { "ignoreCase": true }],
|
"react/jsx-sort-props": [2, { "ignoreCase": true }],
|
||||||
"react/jsx-uses-react": 2,
|
"react/jsx-uses-react": 2,
|
||||||
@ -237,6 +248,15 @@
|
|||||||
"react/react-in-jsx-scope": 2,
|
"react/react-in-jsx-scope": 2,
|
||||||
"react/self-closing-comp": 2,
|
"react/self-closing-comp": 2,
|
||||||
"react/wrap-multilines": 2,
|
"react/wrap-multilines": 2,
|
||||||
"react/jsx-closing-bracket-location": [ 2, { "selfClosing": "line-aligned", "nonEmpty": "props-aligned" } ]
|
"react/jsx-closing-bracket-location": [ 2, { "selfClosing": "line-aligned", "nonEmpty": "props-aligned" } ],
|
||||||
|
|
||||||
|
"import/no-unresolved": 2,
|
||||||
|
"import/named": 2,
|
||||||
|
"import/namespace": 2,
|
||||||
|
"import/default": 2,
|
||||||
|
"import/export": 2,
|
||||||
|
"import/imports-first": 2,
|
||||||
|
"import/no-duplicates": 2,
|
||||||
|
"import/newline-after-import": 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { Observable } from 'rx';
|
import { Observable } from 'rx';
|
||||||
|
/* eslint-disable import/no-unresolved */
|
||||||
import loopProtect from 'loop-protect';
|
import loopProtect from 'loop-protect';
|
||||||
|
/* eslint-enable import/no-unresolved */
|
||||||
|
|
||||||
import { updateContents } from '../../common/utils/polyvinyl';
|
import { updateContents } from '../../common/utils/polyvinyl';
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import Rx, { Observable, Subject } from 'rx';
|
import Rx, { Observable, Subject } from 'rx';
|
||||||
|
/* eslint-disable import/no-unresolved */
|
||||||
import loopProtect from 'loop-protect';
|
import loopProtect from 'loop-protect';
|
||||||
|
/* eslint-enable import/no-unresolved */
|
||||||
import types from '../../common/app/routes/challenges/redux/types';
|
import types from '../../common/app/routes/challenges/redux/types';
|
||||||
import {
|
import {
|
||||||
updateOutput,
|
updateOutput,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { hardGoTo } from '../../common/app/redux/types';
|
import types from '../../common/app/redux/types';
|
||||||
|
|
||||||
|
const { hardGoTo } = types;
|
||||||
export default function hardGoToSaga(action$, getState, { history }) {
|
export default function hardGoToSaga(action$, getState, { history }) {
|
||||||
return action$
|
return action$
|
||||||
.filter(({ type }) => type === hardGoTo)
|
.filter(({ type }) => type === hardGoTo)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { Observable } from 'rx';
|
import { Observable } from 'rx';
|
||||||
import { initWindowHeight } from '../../common/app/redux/types';
|
import types from '../../common/app/redux/types';
|
||||||
import { updateWindowHeight } from '../../common/app/redux/actions';
|
import { updateWindowHeight } from '../../common/app/redux/actions';
|
||||||
|
|
||||||
|
const { initWindowHeight } = types;
|
||||||
function getWindowSize(document, window) {
|
function getWindowSize(document, window) {
|
||||||
const body = document.getElementsByTagName('body')[0];
|
const body = document.getElementsByTagName('body')[0];
|
||||||
return window.innerHeight ||
|
return window.innerHeight ||
|
||||||
|
@ -32,6 +32,7 @@ export const addUser = createAction(
|
|||||||
entities => ({ entities })
|
entities => ({ entities })
|
||||||
);
|
);
|
||||||
export const updateThisUser = createAction(types.updateThisUser);
|
export const updateThisUser = createAction(types.updateThisUser);
|
||||||
|
export const showSignIn = createAction(types.showSignIn);
|
||||||
|
|
||||||
// updateUserPoints(username: String, points: Number) => Action
|
// updateUserPoints(username: String, points: Number) => Action
|
||||||
export const updateUserPoints = createAction(
|
export const updateUserPoints = createAction(
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import {
|
import types from './types';
|
||||||
updateUserPoints,
|
|
||||||
updateCompletedChallenges
|
|
||||||
} from './types';
|
|
||||||
|
|
||||||
|
const { updateUserPoints, updateCompletedChallenges } = types;
|
||||||
const initialState = {
|
const initialState = {
|
||||||
superBlock: {},
|
superBlock: {},
|
||||||
block: {},
|
block: {},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Observable } from 'rx';
|
import { Observable } from 'rx';
|
||||||
import { fetchUser } from './types';
|
import types from './types';
|
||||||
import {
|
import {
|
||||||
addUser,
|
addUser,
|
||||||
updateThisUser,
|
updateThisUser,
|
||||||
@ -8,6 +8,8 @@ import {
|
|||||||
showSignIn
|
showSignIn
|
||||||
} from './actions';
|
} from './actions';
|
||||||
|
|
||||||
|
const { fetchUser } = types;
|
||||||
|
|
||||||
export default function getUserSaga(action$, getState, { services }) {
|
export default function getUserSaga(action$, getState, { services }) {
|
||||||
return action$
|
return action$
|
||||||
.filter(action => action.type === fetchUser)
|
.filter(action => action.type === fetchUser)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export { default as reducer } from './reducer';
|
|
||||||
export { default as actions } from './actions';
|
|
||||||
export { default as types } from './types';
|
|
||||||
|
|
||||||
import fetchUserSaga from './fetch-user-saga';
|
import fetchUserSaga from './fetch-user-saga';
|
||||||
|
|
||||||
|
export { default as reducer } from './reducer';
|
||||||
|
export * as actions from './actions';
|
||||||
|
export { default as types } from './types';
|
||||||
export const sagas = [ fetchUserSaga ];
|
export const sagas = [ fetchUserSaga ];
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import { resetForm, reduxForm } from 'redux-form';
|
import { reduxForm } from 'redux-form';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
FormGroup,
|
FormGroup,
|
||||||
@ -25,7 +25,6 @@ const propTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const bindableActions = {
|
const bindableActions = {
|
||||||
resetForm,
|
|
||||||
submitChallenge,
|
submitChallenge,
|
||||||
showProjectSubmit
|
showProjectSubmit
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
import { Observable } from 'rx';
|
import { Observable } from 'rx';
|
||||||
import { challengeSelector } from './selectors';
|
import { challengeSelector } from './selectors';
|
||||||
import {
|
import types from './types';
|
||||||
fetchChallenge,
|
|
||||||
fetchChallenges,
|
|
||||||
replaceChallenge
|
|
||||||
} from './types';
|
|
||||||
import {
|
import {
|
||||||
fetchChallengeCompleted,
|
fetchChallengeCompleted,
|
||||||
fetchChallengesCompleted,
|
fetchChallengesCompleted,
|
||||||
@ -13,9 +9,11 @@ import {
|
|||||||
} from './actions';
|
} from './actions';
|
||||||
import {
|
import {
|
||||||
delayedRedirect,
|
delayedRedirect,
|
||||||
createErrorObserable
|
createErrorObservable
|
||||||
} from '../../../redux/actions';
|
} from '../../../redux/actions';
|
||||||
|
|
||||||
|
const { fetchChallenge, fetchChallenges, replaceChallenge } = types;
|
||||||
|
|
||||||
function createNameIdMap(entities) {
|
function createNameIdMap(entities) {
|
||||||
const { challenge } = entities;
|
const { challenge } = entities;
|
||||||
return {
|
return {
|
||||||
@ -77,6 +75,6 @@ export default function fetchChallengesSaga(action$, getState, { services }) {
|
|||||||
initMap(entities, result),
|
initMap(entities, result),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.catch(createErrorObserable);
|
.catch(createErrorObservable);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
export actions from './actions';
|
|
||||||
export reducer from './reducer';
|
|
||||||
export types from './types';
|
|
||||||
|
|
||||||
import fetchChallengesSaga from './fetch-challenges-saga';
|
import fetchChallengesSaga from './fetch-challenges-saga';
|
||||||
import completionSaga from './completion-saga';
|
import completionSaga from './completion-saga';
|
||||||
import nextChallengeSaga from './next-challenge-saga';
|
import nextChallengeSaga from './next-challenge-saga';
|
||||||
import answerSaga from './answer-saga';
|
import answerSaga from './answer-saga';
|
||||||
|
|
||||||
|
export * as actions from './actions';
|
||||||
|
export reducer from './reducer';
|
||||||
|
export types from './types';
|
||||||
|
|
||||||
export projectNormalizer from './project-normalizer';
|
export projectNormalizer from './project-normalizer';
|
||||||
|
|
||||||
export const sagas = [
|
export const sagas = [
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Observable } from 'rx';
|
import { Observable } from 'rx';
|
||||||
import { push } from 'react-router-redux';
|
import { push } from 'react-router-redux';
|
||||||
import { moveToNextChallenge } from './types';
|
import types from './types';
|
||||||
import { resetUi, updateCurrentChallenge } from './actions';
|
import { resetUi, updateCurrentChallenge } from './actions';
|
||||||
import { createErrorObservable, makeToast } from '../../../redux/actions';
|
import { createErrorObservable, makeToast } from '../../../redux/actions';
|
||||||
import {
|
import {
|
||||||
@ -10,6 +10,8 @@ import {
|
|||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { randomVerb } from '../../../utils/get-words';
|
import { randomVerb } from '../../../utils/get-words';
|
||||||
|
|
||||||
|
const { moveToNextChallenge } = types;
|
||||||
|
|
||||||
export default function nextChallengeSaga(actions$, getState) {
|
export default function nextChallengeSaga(actions$, getState) {
|
||||||
return actions$
|
return actions$
|
||||||
.filter(({ type }) => type === moveToNextChallenge)
|
.filter(({ type }) => type === moveToNextChallenge)
|
||||||
|
@ -7,8 +7,8 @@ import {
|
|||||||
getUsernameFromProvider,
|
getUsernameFromProvider,
|
||||||
getSocialProvider
|
getSocialProvider
|
||||||
} from '../../server/utils/auth';
|
} from '../../server/utils/auth';
|
||||||
|
import { defaultProfileImage } from '../utils/constantStrings.json';
|
||||||
|
|
||||||
const { defaultProfileImage } = require('../utils/constantStrings.json');
|
|
||||||
const githubRegex = (/github/i);
|
const githubRegex = (/github/i);
|
||||||
const debug = debugFactory('fcc:models:userIdent');
|
const debug = debugFactory('fcc:models:userIdent');
|
||||||
|
|
||||||
|
@ -127,6 +127,7 @@
|
|||||||
"chunk-manifest-webpack-plugin": "0.1.0",
|
"chunk-manifest-webpack-plugin": "0.1.0",
|
||||||
"del": "^2.2.0",
|
"del": "^2.2.0",
|
||||||
"eslint": "^3.1.0",
|
"eslint": "^3.1.0",
|
||||||
|
"eslint-plugin-import": "^1.9.2",
|
||||||
"eslint-plugin-react": "^5.1.1",
|
"eslint-plugin-react": "^5.1.1",
|
||||||
"gulp": "^3.9.0",
|
"gulp": "^3.9.0",
|
||||||
"gulp-babel": "^6.1.1",
|
"gulp-babel": "^6.1.1",
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import request from 'request';
|
import request from 'request';
|
||||||
import constantStrings from '../utils/constantStrings.json';
|
import constantStrings from '../utils/constantStrings.json';
|
||||||
import testimonials from '../resources/testimonials.json';
|
import testimonials from '../resources/testimonials.json';
|
||||||
import secrets from '../../config/secrets';
|
|
||||||
|
const githubClient = process.env.GITHUB_ID;
|
||||||
|
const githubSecret = process.env.GITHUB_SECRET;
|
||||||
|
|
||||||
module.exports = function(app) {
|
module.exports = function(app) {
|
||||||
const router = app.loopback.Router();
|
const router = app.loopback.Router();
|
||||||
@ -258,9 +260,9 @@ module.exports = function(app) {
|
|||||||
[
|
[
|
||||||
'https://api.github.com/repos/freecodecamp/',
|
'https://api.github.com/repos/freecodecamp/',
|
||||||
'freecodecamp/pulls?client_id=',
|
'freecodecamp/pulls?client_id=',
|
||||||
secrets.github.clientID,
|
githubClient,
|
||||||
'&client_secret=',
|
'&client_secret=',
|
||||||
secrets.github.clientSecret
|
githubSecret
|
||||||
].join(''),
|
].join(''),
|
||||||
githubHeaders,
|
githubHeaders,
|
||||||
function(err, status1, pulls) {
|
function(err, status1, pulls) {
|
||||||
@ -273,9 +275,9 @@ module.exports = function(app) {
|
|||||||
[
|
[
|
||||||
'https://api.github.com/repos/freecodecamp/',
|
'https://api.github.com/repos/freecodecamp/',
|
||||||
'freecodecamp/issues?client_id=',
|
'freecodecamp/issues?client_id=',
|
||||||
secrets.github.clientID,
|
githubClient,
|
||||||
'&client_secret=',
|
'&client_secret=',
|
||||||
secrets.github.clientSecret
|
githubSecret
|
||||||
].join(''),
|
].join(''),
|
||||||
githubHeaders,
|
githubHeaders,
|
||||||
function(err, status2, issues) {
|
function(err, status2, issues) {
|
||||||
|
@ -12,7 +12,11 @@ import {
|
|||||||
|
|
||||||
import certTypes from '../utils/certTypes.json';
|
import certTypes from '../utils/certTypes.json';
|
||||||
|
|
||||||
import { ifNoUser401, ifNoUserRedirectTo } from '../utils/middleware';
|
import {
|
||||||
|
ifNoUser401,
|
||||||
|
ifNoUserRedirectTo,
|
||||||
|
flashIfNotVerified
|
||||||
|
} from '../utils/middleware';
|
||||||
import { observeQuery } from '../utils/rx';
|
import { observeQuery } from '../utils/rx';
|
||||||
import {
|
import {
|
||||||
prepUniqueDays,
|
prepUniqueDays,
|
||||||
@ -20,8 +24,6 @@ import {
|
|||||||
calcLongestStreak
|
calcLongestStreak
|
||||||
} from '../utils/user-stats';
|
} from '../utils/user-stats';
|
||||||
|
|
||||||
import { flashIfNotVerified } from '../utils/middleware';
|
|
||||||
|
|
||||||
const debug = debugFactory('fcc:boot:user');
|
const debug = debugFactory('fcc:boot:user');
|
||||||
const sendNonUserToMap = ifNoUserRedirectTo('/map');
|
const sendNonUserToMap = ifNoUserRedirectTo('/map');
|
||||||
const certIds = {
|
const certIds = {
|
||||||
|
@ -2,4 +2,5 @@
|
|||||||
// or mocha.
|
// or mocha.
|
||||||
require('babel-register');
|
require('babel-register');
|
||||||
var app = require('./server');
|
var app = require('./server');
|
||||||
|
|
||||||
app.start();
|
app.start();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import cookieParser from 'cookie-parser';
|
import cookieParser from 'cookie-parser';
|
||||||
import secrets from '../../config/secrets';
|
|
||||||
|
|
||||||
export default cookieParser.bind(cookieParser, secrets.cookieSecret);
|
const cookieSecret = process.env.COOKIE_SECRET;
|
||||||
|
export default cookieParser.bind(cookieParser, cookieSecret);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import manifest from '../rev-manifest';
|
import manifest from '../rev-manifest';
|
||||||
|
/* eslint-disable import/default */
|
||||||
import config from '../../webpack.config';
|
import config from '../../webpack.config';
|
||||||
|
/* eslint-enable import/default */
|
||||||
|
|
||||||
let chunkManifest;
|
let chunkManifest;
|
||||||
try {
|
try {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import session from 'express-session';
|
import session from 'express-session';
|
||||||
import MongoStoreFactory from 'connect-mongo';
|
import MongoStoreFactory from 'connect-mongo';
|
||||||
import secrets from '../../config/secrets';
|
|
||||||
|
|
||||||
const MongoStore = MongoStoreFactory(session);
|
const MongoStore = MongoStoreFactory(session);
|
||||||
|
const sessionSecret = process.env.SESSION_SECRET;
|
||||||
|
const url = process.env.MONGODB || process.env.MONGOHQ_URL;
|
||||||
|
|
||||||
export default function sessionsMiddleware() {
|
export default function sessionsMiddleware() {
|
||||||
return session({
|
return session({
|
||||||
@ -10,7 +11,7 @@ export default function sessionsMiddleware() {
|
|||||||
cookie: { maxAge: 900 * 24 * 60 * 60 * 1000 },
|
cookie: { maxAge: 900 * 24 * 60 * 60 * 1000 },
|
||||||
resave: true,
|
resave: true,
|
||||||
saveUninitialized: true,
|
saveUninitialized: true,
|
||||||
secret: secrets.sessionSecret,
|
secret: sessionSecret,
|
||||||
store: new MongoStore({ url: secrets.db })
|
store: new MongoStore({ url })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
var successRedirect = '/';
|
var successRedirect = '/';
|
||||||
var failureRedirect = '/signin';
|
var failureRedirect = '/signin';
|
||||||
var linkFailureRedirect = '/account';
|
var linkFailureRedirect = '/account';
|
||||||
module.exports = {
|
|
||||||
|
export default {
|
||||||
local: {
|
local: {
|
||||||
provider: 'local',
|
provider: 'local',
|
||||||
module: 'passport-local',
|
module: 'passport-local',
|
||||||
|
@ -5,6 +5,7 @@ var startTime = Date.now();
|
|||||||
var timeoutHandler;
|
var timeoutHandler;
|
||||||
// this is where server starts booting up
|
// this is where server starts booting up
|
||||||
var app = require('./server');
|
var app = require('./server');
|
||||||
|
|
||||||
console.log('waiting for db to connect');
|
console.log('waiting for db to connect');
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
require('dotenv').load();
|
require('dotenv').load();
|
||||||
var pmx = require('pmx');
|
var pmx = require('pmx');
|
||||||
|
|
||||||
pmx.init();
|
pmx.init();
|
||||||
|
|
||||||
var _ = require('lodash'),
|
var _ = require('lodash'),
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import dedent from 'dedent';
|
import dedent from 'dedent';
|
||||||
import debugFactory from 'debug';
|
import debugFactory from 'debug';
|
||||||
import { Observable } from 'rx';
|
import { Observable } from 'rx';
|
||||||
|
|
||||||
import commitGoals from './commit-goals.json';
|
import commitGoals from './commit-goals.json';
|
||||||
|
|
||||||
const debug = debugFactory('fcc:utils/commit');
|
const debug = debugFactory('fcc:utils/commit');
|
||||||
|
|
||||||
export { commitGoals };
|
export { commitGoals };
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
exports.blacklistedUsernames = [
|
export const blacklistedUsernames = [
|
||||||
'bonfire',
|
'bonfire',
|
||||||
'account',
|
'account',
|
||||||
'user',
|
'user',
|
||||||
|
@ -1,101 +1,22 @@
|
|||||||
var cheerio = require('cheerio'),
|
export function dasherize(name) {
|
||||||
request = require('request'),
|
return ('' + name)
|
||||||
MDNlinks = require('../../seed/bonfireMDNlinks'),
|
.toLowerCase()
|
||||||
resources = require('./resources.json');
|
.replace(/\s/g, '-')
|
||||||
|
.replace(/[^a-z0-9\-\.]/gi, '')
|
||||||
|
.replace(/\:/g, '');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
export function nameify(str) {
|
||||||
* Cached values
|
return ('' + str)
|
||||||
*/
|
.replace(/[^a-zA-Z0-9\s]/g, '')
|
||||||
|
.replace(/\:/g, '');
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
export function unDasherize(name) {
|
||||||
dasherize: function dasherize(name) {
|
return ('' + name)
|
||||||
return ('' + name)
|
// replace dash with space
|
||||||
.toLowerCase()
|
.replace(/\-/g, ' ')
|
||||||
.replace(/\s/g, '-')
|
// strip nonalphanumarics chars except whitespace
|
||||||
.replace(/[^a-z0-9\-\.]/gi, '')
|
.replace(/[^a-zA-Z\d\s]/g, '')
|
||||||
.replace(/\:/g, '');
|
.trim();
|
||||||
},
|
}
|
||||||
|
|
||||||
nameify: function nameify(str) {
|
|
||||||
return ('' + str)
|
|
||||||
.replace(/[^a-zA-Z0-9\s]/g, '')
|
|
||||||
.replace(/\:/g, '');
|
|
||||||
},
|
|
||||||
|
|
||||||
unDasherize: function unDasherize(name) {
|
|
||||||
return ('' + name)
|
|
||||||
// replace dash with space
|
|
||||||
.replace(/\-/g, ' ')
|
|
||||||
// strip nonalphanumarics chars except whitespace
|
|
||||||
.replace(/[^a-zA-Z\d\s]/g, '')
|
|
||||||
.trim();
|
|
||||||
},
|
|
||||||
|
|
||||||
randomPhrase: function() {
|
|
||||||
return resources.phrases[
|
|
||||||
Math.floor(Math.random() * resources.phrases.length)
|
|
||||||
];
|
|
||||||
},
|
|
||||||
|
|
||||||
randomVerb: function() {
|
|
||||||
return resources.verbs[
|
|
||||||
Math.floor(Math.random() * resources.verbs.length)
|
|
||||||
];
|
|
||||||
},
|
|
||||||
|
|
||||||
randomCompliment: function() {
|
|
||||||
return resources.compliments[
|
|
||||||
Math.floor(Math.random() * resources.compliments.length)
|
|
||||||
];
|
|
||||||
},
|
|
||||||
|
|
||||||
whichEnvironment: function() {
|
|
||||||
return process.env.NODE_ENV;
|
|
||||||
},
|
|
||||||
|
|
||||||
getURLTitle: function(url, callback) {
|
|
||||||
var result = {
|
|
||||||
title: '',
|
|
||||||
image: '',
|
|
||||||
url: '',
|
|
||||||
description: ''
|
|
||||||
};
|
|
||||||
request(url, function(err, response, body) {
|
|
||||||
if (err || response.statusCode !== 200) {
|
|
||||||
return callback(new Error('failed'));
|
|
||||||
}
|
|
||||||
var $ = cheerio.load(body);
|
|
||||||
var metaDescription = $("meta[name='description']");
|
|
||||||
var metaImage = $("meta[property='og:image']");
|
|
||||||
var urlImage = metaImage.attr('content') ?
|
|
||||||
metaImage.attr('content') :
|
|
||||||
'';
|
|
||||||
|
|
||||||
var metaTitle = $('title');
|
|
||||||
var description = metaDescription.attr('content') ?
|
|
||||||
metaDescription.attr('content') :
|
|
||||||
'';
|
|
||||||
|
|
||||||
result.title = metaTitle.text().length < 90 ?
|
|
||||||
metaTitle.text() :
|
|
||||||
metaTitle.text().slice(0, 87) + '...';
|
|
||||||
|
|
||||||
result.image = urlImage;
|
|
||||||
result.description = description;
|
|
||||||
return callback(null, result);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
getMDNLinks: function(links) {
|
|
||||||
if (!links) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
// takes in an array of links, which are strings
|
|
||||||
|
|
||||||
// for each key value, push the corresponding link
|
|
||||||
// from the MDNlinks object into a new array
|
|
||||||
return links.map(function(value) {
|
|
||||||
return MDNlinks[value];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
Reference in New Issue
Block a user