|
|
@ -93,19 +93,28 @@ module.exports = function(Categories) {
|
|
|
|
if (category.posts.length) {
|
|
|
|
if (category.posts.length) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var latestPost;
|
|
|
|
var posts = [];
|
|
|
|
category.children.forEach(function(children) {
|
|
|
|
getPostsRecursive(category, posts);
|
|
|
|
if (children.posts.length && (!latestPost || (latestPost && latestPost.timestamp < children.posts[0].timestamp))) {
|
|
|
|
|
|
|
|
latestPost = children.posts[0];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (latestPost) {
|
|
|
|
posts.sort(function(a, b) {
|
|
|
|
category.posts = [latestPost];
|
|
|
|
return b.timestamp - a.timestamp;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if (posts.length) {
|
|
|
|
|
|
|
|
category.posts = [posts[0]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getPostsRecursive(category, posts) {
|
|
|
|
|
|
|
|
category.posts.forEach(function(p) {
|
|
|
|
|
|
|
|
posts.push(p);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
category.children.forEach(function(child) {
|
|
|
|
|
|
|
|
getPostsRecursive(child, posts);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function assignPostsToCategories(categories, posts) {
|
|
|
|
function assignPostsToCategories(categories, posts) {
|
|
|
|
categories.forEach(function(category) {
|
|
|
|
categories.forEach(function(category) {
|
|
|
|
category.posts = posts.filter(function(post) {
|
|
|
|
category.posts = posts.filter(function(post) {
|
|
|
|