mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-12 10:52:47 +00:00
updated bunch of file paths and changed the way posts are loaded
This commit is contained in:
86
node_modules/mongoose/examples/schema/schema.js
generated
vendored
86
node_modules/mongoose/examples/schema/schema.js
generated
vendored
@@ -3,8 +3,8 @@
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var mongoose = require('../../lib')
|
||||
, Schema = mongoose.Schema;
|
||||
var mongoose = require('../../lib'),
|
||||
Schema = mongoose.Schema;
|
||||
|
||||
/**
|
||||
* Schema definition
|
||||
@@ -15,28 +15,45 @@ var mongoose = require('../../lib')
|
||||
var Comment = new Schema();
|
||||
|
||||
Comment.add({
|
||||
title : { type: String, index: true }
|
||||
, date : Date
|
||||
, body : String
|
||||
, comments : [Comment]
|
||||
title: {
|
||||
type: String,
|
||||
index: true
|
||||
},
|
||||
date: Date,
|
||||
body: String,
|
||||
comments: [Comment]
|
||||
});
|
||||
|
||||
var BlogPost = new Schema({
|
||||
title : { type: String, index: true }
|
||||
, slug : { type: String, lowercase: true, trim: true }
|
||||
, date : Date
|
||||
, buf : Buffer
|
||||
, comments : [Comment]
|
||||
, creator : Schema.ObjectId
|
||||
title: {
|
||||
type: String,
|
||||
index: true
|
||||
},
|
||||
slug: {
|
||||
type: String,
|
||||
lowercase: true,
|
||||
trim: true
|
||||
},
|
||||
date: Date,
|
||||
buf: Buffer,
|
||||
comments: [Comment],
|
||||
creator: Schema.ObjectId
|
||||
});
|
||||
|
||||
var Person = new Schema({
|
||||
name: {
|
||||
first: String
|
||||
, last : String
|
||||
name: {
|
||||
first: String,
|
||||
last : String
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
index: {
|
||||
unique: true,
|
||||
sparse: true
|
||||
}
|
||||
, email: { type: String, required: true, index: { unique: true, sparse: true } }
|
||||
, alive: Boolean
|
||||
},
|
||||
alive: Boolean
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -44,18 +61,19 @@ var Person = new Schema({
|
||||
*/
|
||||
|
||||
BlogPost.path('date')
|
||||
.default(function(){
|
||||
return new Date()
|
||||
})
|
||||
.set(function(v){
|
||||
return v == 'now' ? new Date() : v;
|
||||
});
|
||||
.default(function() {
|
||||
return new Date();
|
||||
})
|
||||
.set(function(v) {
|
||||
return v == 'now' ? new Date() : v;
|
||||
});
|
||||
|
||||
/**
|
||||
* Pre hook.
|
||||
*/
|
||||
|
||||
BlogPost.pre('save', function(next, done){
|
||||
BlogPost.pre('save', function(next, done) {
|
||||
/* global emailAuthor */
|
||||
emailAuthor(done); // some async function
|
||||
next();
|
||||
});
|
||||
@@ -64,33 +82,33 @@ BlogPost.pre('save', function(next, done){
|
||||
* Methods
|
||||
*/
|
||||
|
||||
BlogPost.methods.findCreator = function (callback) {
|
||||
BlogPost.methods.findCreator = function(callback) {
|
||||
return this.db.model('Person').findById(this.creator, callback);
|
||||
}
|
||||
};
|
||||
|
||||
BlogPost.statics.findByTitle = function (title, callback) {
|
||||
BlogPost.statics.findByTitle = function(title, callback) {
|
||||
return this.find({ title: title }, callback);
|
||||
}
|
||||
};
|
||||
|
||||
BlogPost.methods.expressiveQuery = function (creator, date, callback) {
|
||||
BlogPost.methods.expressiveQuery = function(creator, date, callback) {
|
||||
return this.find('creator', creator).where('date').gte(date).run(callback);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Plugins
|
||||
*/
|
||||
|
||||
function slugGenerator (options){
|
||||
function slugGenerator(options) {
|
||||
options = options || {};
|
||||
var key = options.key || 'title';
|
||||
|
||||
return function slugGenerator(schema){
|
||||
schema.path(key).set(function(v){
|
||||
return function slugGenerator(schema) {
|
||||
schema.path(key).set(function(v) {
|
||||
this.slug = v.toLowerCase().replace(/[^a-z0-9]/g, '').replace(/-+/g, '');
|
||||
return v;
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
BlogPost.plugin(slugGenerator());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user