Skip to content

Commit

Permalink
Fixed category #101
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Mar 2, 2013
1 parent 0dc8373 commit 2f8572f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/plugins/processor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,23 @@ extend.processor.register(/^_posts\/([^_](?:(?!\/_).)*)$/, function(file, callba
}

if (meta.categories){
var cats = [];

var catPath = _.map(meta.categories, function(item){
return escape(item);
}).join('/');

var cats = [];
_.each(meta.categories, function(item, i, arr){
var path = _.map(arr.slice(0, i + 1), function(item){
return escape(item);
}).join('/') + '/';

meta.categories.forEach(function(cat){
var data = dbCats.findOne({path: catPath});
var data = dbCats.findOne({path: path});
if (data){
dbCats.update(data._id, {posts: {$addToSet: _id}});
cats.push(data._id);
} else {
dbCats.insert({name: cat, path: catPath + '/', posts: [_id]}, function(cat){
dbCats.insert({name: item, path: path, posts: [_id]}, function(cat){
cats.push(cat._id);
});
}
Expand Down

0 comments on commit 2f8572f

Please sign in to comment.