add challenge order to individual challenge

This commit is contained in:
Berkeley Martinez
2015-08-09 07:40:16 -07:00
parent b1e34f8cc8
commit 2476f35309
2 changed files with 10 additions and 2 deletions

View File

@ -19,6 +19,9 @@
"type": {
"type": "string"
},
"order": {
"type": "number"
},
"dashedName": {
"type": "string"
},

View File

@ -38,14 +38,19 @@ Challenge.destroyAll(function(err, info) {
}
challenges.forEach(function(file) {
var challengeSpec = require('./challenges/' + file);
var order = challengeSpec.order;
var challenges = challengeSpec.challenges
.map(function(challenge) {
.map(function(challenge, index) {
// NOTE(berks): add title for displaying in views
challenge.name =
_.capitalize(challenge.type) +
': ' +
challenge.title.replace(/[^a-zA-Z0-9\s]/g, '');
challenge.dashedName = challenge.name.toLowerCase().replace(/\s/g, '-');
challenge.dashedName = challenge.name
.toLowerCase()
.replace(/\:/g, '')
.replace(/\s/g, '-');
challenge.order = +('' + order + (index + 1));
return challenge;
});