Add character names to the end of their URL's

Closes #21, makes links to characters human readable
This commit is contained in:
Stefan Zermatten
2017-07-13 13:14:04 +02:00
parent 089feae26f
commit 3227cd0934
9 changed files with 59 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ Characters = new Mongo.Collection("characters");
Schemas.Character = new SimpleSchema({
//strings
name: {type: String, defaultValue: "", trim: false, optional: true},
urlName: {type: String, defaultValue: "", trim: false, optional: true},
alignment: {type: String, defaultValue: "", trim: false, optional: true},
gender: {type: String, defaultValue: "", trim: false, optional: true},
race: {type: String, defaultValue: "", trim: false, optional: true},
@@ -540,6 +541,12 @@ if (Meteor.isServer){
Items .remove({charId: character._id});
Containers .remove({charId: character._id});
});
Characters.after.update(function(userId, doc, fieldNames, modifier, options) {
if (_.contains(fieldNames, "name")){
var urlName = getSlug(doc.name, {maintainCase: true});
Characters.update(doc._id, {$set: {urlName}});
}
});
}
Characters.allow({