var moment = require("moment"); var _ = require("lodash"); var fs = require('fs'); var mkdirp = require('mkdirp'); var jade = require('jade'); var markdown = require( "markdown" ).markdown; var path = require('path'); var schemas = require('./schemas.js'); var config = require("./config.js").config; var Post = function(data) { this.data = this.sanitize(data); } //////////////////////////////////////////////////////////////////////////////////////// // Prototype Setup //////////////////////////////////////////////////////////////////////////////////////// Post.prototype.data = {} Post.prototype.get = function (name) { return this.data[name]; } Post.prototype.set = function (name, value) { this.data[name] = value; } Post.prototype.toString = function () { return 'Post: ' + this.get('title') + ' - ' + this.getShortDate(); } Post.prototype.sanitize = function (data) { data = data || {}; schema = schemas.post; return _.pick(_.defaults(data, schema), _.keys(schema)); } Post.prototype.save = function (date, callback) { var self = this; if (date) { this.set("updatedDate", date); } else { this.set("updatedDate", new Date()); } this.data = this.sanitize(this.data); db.collection("posts").update({uuid: this.get("uuid")}, this.data, {upsert: true}, function(err) { callback(err); }); } //////////////////////////////////////////////////////////////////////////////////////// // Prototype Functions //////////////////////////////////////////////////////////////////////////////////////// // Parse a string of tags // Returns a list of tags Post.prototype.tagPost = function(str) { this.set("tags", []); // we don't need no stinking commas var str = str.replace(/,/g,''); // remove accents, swap ñ for n, etc var from = "àáäâèéëêìíïîòóöôùúüûñç·/,:;&%"; var to = "aaaaeeeeiiiioooouuuunc-------"; for (var i=0, l=from.length ; i= this.updatedDate) && \ this.published' }).toArray( function (err, docs) { if (err) console.log(err); posts = []; if (docs) { for (i=0; i= new Date('+year+', '+month+'-1, 1, 0, 0, 0)) \ && (this.postDate <= new Date('+year+', '+month+', 0, 23, 59, 59))' }, {sort: [['postDate', 'desc'],['title', 'asc']]} ).toArray(function (err, docs) { if (!err) { console.log('Found '+docs.length+' posts from '+year+'/'+month); posts = [] for (i=0; i= start) && (this.postDate <= end)' }).toArray(function (err, docs) { posts = [] for (i=0; i