mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 18:56:15 +01:00
recursive #3227
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user