mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 10:46:14 +01:00
recursive #3227
This commit is contained in:
@@ -93,19 +93,28 @@ module.exports = function(Categories) {
|
||||
if (category.posts.length) {
|
||||
return;
|
||||
}
|
||||
var latestPost;
|
||||
category.children.forEach(function(children) {
|
||||
if (children.posts.length && (!latestPost || (latestPost && latestPost.timestamp < children.posts[0].timestamp))) {
|
||||
latestPost = children.posts[0];
|
||||
}
|
||||
});
|
||||
var posts = [];
|
||||
getPostsRecursive(category, posts);
|
||||
|
||||
if (latestPost) {
|
||||
category.posts = [latestPost];
|
||||
posts.sort(function(a, b) {
|
||||
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) {
|
||||
categories.forEach(function(category) {
|
||||
category.posts = posts.filter(function(post) {
|
||||
|
||||
Reference in New Issue
Block a user