add title field to challenges

This commit is contained in:
Berkeley Martinez
2015-07-13 18:30:51 -07:00
parent de1d931b82
commit 3df60136e8
2 changed files with 13 additions and 1 deletions

View File

@ -8,6 +8,9 @@
"type": "string", "type": "string",
"unique": true "unique": true
}, },
"title": {
"type": "string"
},
"dashedName": { "dashedName": {
"type": "string" "type": "string"
}, },

View File

@ -7,6 +7,8 @@ var fs = require('fs'),
nonprofits = require('./nonprofits.json'), nonprofits = require('./nonprofits.json'),
jobs = require('./jobs.json'); jobs = require('./jobs.json');
var challangesRegex = /^(bonfire:|waypoint:|zipline:|basejump:|hikes:)/i;
function getFilesFor(dir) { function getFilesFor(dir) {
return fs.readdirSync(path.join(__dirname, '/' + dir)); return fs.readdirSync(path.join(__dirname, '/' + dir));
} }
@ -38,8 +40,15 @@ Challenge.destroyAll(function(err, info) {
console.log('Deleted ', info); console.log('Deleted ', info);
} }
challenges.forEach(function(file) { challenges.forEach(function(file) {
var challenges = require('./challenges/' + file).challenges
.map(function(challenge) {
// NOTE(berks): add title for displaying in views
challenge.title = challenge.name.replace(challangesRegex, '').trim();
return challenge;
});
Challenge.create( Challenge.create(
require('./challenges/' + file).challenges, challenges,
function(err) { function(err) {
if (err) { if (err) {
console.log(err); console.log(err);