Static copy was bailing on unlinking the directory, now just overcopies

This commit is contained in:
Andrew Davidson 2016-01-24 12:02:43 -05:00
parent 1c9c8b1a5a
commit 634bddc093
2 changed files with 38 additions and 27 deletions

63
post.js
View file

@ -162,9 +162,9 @@ Post.prototype.build = function (callback) {
year = moment(this.get("postDate")).format("YYYY"); year = moment(this.get("postDate")).format("YYYY");
month = moment(this.get("postDate")).format("MM"); month = moment(this.get("postDate")).format("MM");
// Post.buildYearIndex(year, function (err) { Post.buildYearIndex(year, function (err) {
// if (err) console.log(err); if (err) console.log(err);
// }); });
Post.buildMonthIndex(year, month, function (err) { Post.buildMonthIndex(year, month, function (err) {
if (err) console.log(err); if (err) console.log(err);
}); });
@ -325,7 +325,7 @@ Post.getNeedsUpload = function (callback) {
Post.buildMonthIndex = function (year, month, callback) { Post.buildMonthIndex = function (year, month, callback) {
console.log('Rendering month index: '+year+'/'+month); console.log('Rendering month index: '+year+'/'+month);
directory = config.buildDir var directory = config.buildDir
directory += "/blog/"; directory += "/blog/";
directory += year + '/' + month + '/'; directory += year + '/' + month + '/';
@ -334,7 +334,8 @@ Post.buildMonthIndex = function (year, month, callback) {
if (!err) { if (!err) {
db.collection('posts').find({ db.collection('posts').find({
$where: '(this.postDate >= new Date('+year+', '+month+'-1, 1, 0, 0, 0)) \ $where: '(this.postDate >= new Date('+year+', '+month+'-1, 1, 0, 0, 0)) \
&& (this.postDate <= new Date('+year+', '+month+', 0, 23, 59, 59))' && (this.postDate <= new Date('+year+', '+month+', 0, 23, 59, 59)) \
&& this.published'
}, {sort: [['postDate', 'desc'],['title', 'asc']]} }, {sort: [['postDate', 'desc'],['title', 'asc']]}
).toArray(function (err, docs) { ).toArray(function (err, docs) {
if (!err) { if (!err) {
@ -372,35 +373,45 @@ Post.buildMonthIndex = function (year, month, callback) {
Post.buildYearIndex = function (year, callback) { Post.buildYearIndex = function (year, callback) {
console.log('Rendering year index: '+year); console.log('Rendering year index: '+year);
directory = config.buildDir var directory = config.buildDir
directory += "/blog/"; directory += "/blog/";
directory += year + '/'; directory += year + '/';
start = new Date(year, 0, 1, 0, 0, 0); console.log('Finding posts from '+year);
end = new Date((year+1), 0, 0, 23, 59, 59);
console.log('Finding posts between '+start+' and '+end);
mkdirp(directory, function (err) { mkdirp(directory, function (err) {
db.collection('posts').find({ if (!err) {
$where: '(this.postDate >= start) && (this.postDate <= end)' db.collection('posts').find({
}).toArray(function (err, docs) { $where: '(this.postDate >= new Date('+year+', 0, 1, 0, 0, 0)) \
posts = [] && (this.postDate <= new Date('+year+'+1, 0, 0, 23, 59, 59)) \
for (i=0; i<docs.length; i++) { && this.published'
posts.push(new Post(docs[i])); }, {sort: [['postDate', 'desc'],['title', 'asc']]}
} ).toArray(function (err, docs) {
var options = { if (!err) {
pretty: true, console.log('Found '+docs.length+' posts from '+year);
posts: posts, posts = []
title: 'Posts from '+year for (i=0; i<docs.length; i++) {
}; posts.push(new Post(docs[i]));
var jadeOut = jade.renderFile('views/render-post-index.jade', options); }
file = path.join(directory, 'index.html'); var jadeOut = jade.renderFile('views/render-post-index.jade', {
pretty: true,
posts: posts,
title: 'Posts from '+year
});
fs.writeFile(file, jadeOut, 'utf-8', function (err) { file = path.join(directory, 'index.html');
callback(err); console.log(file);
fs.writeFile(file, jadeOut, 'utf-8', function (err) {
callback(err);
});
} else {
callback(err)
}
}); });
}); } else {
callback(err);
}
}); });
} }

View file

@ -2,4 +2,4 @@ article
header header
h3: a(href="#{post.getURL()}") #{post.get("title")} h3: a(href="#{post.getURL()}") #{post.get("title")}
p #{post.getShortDate()} p #{post.getShortDate()}
!{post.renderMarkdown()} | !{post.renderMarkdown()}