nodebb-plugin-homepage-api: Getting content of mainPid?

NodeBB Development
  • Hi everyone
    I was playing around with the homepage-api plugin (modifies the homepage api to return the topics of categories instead of the posts) and I tried modifying it to where it also returns the content of the topic/mainPid but couldn't get it to work correctly. Can anybody help me out?

    this is what I came up with:

                    function getMainPost(topics, callback) {
                       posts.getPostFields(topics.mainPid, ["content"], function (err, data) {
                           console.log(data);
                           var content = data.content;
                           topics.content = content;
                       });
                    }
                
                
                function getRecentTopics(category, callback) {
                    categories.getCategoryTopics(category.cid, 0, parseInt(category.numRecentReplies, 10), uid, function (err, data) {
                        var topics = data.topics;
                        async.each(data.topics, getMainPost, function(err) {
                            next(err, data.topics)
                        });
                
                        category.topics = topics;
                        category.topic_count = topics.length;
                        callback(null);
                    });
                }
                
                async.each(categoryData, getRecentTopics, function (err) {
                    next(err, categoryData);
                });
    
  • nvm, I got it working. I was confused how async.each() worked..! 😣

    here's what I ended up with:

                    function getMainPost(topics, callback) {
                        posts.getPostFields(topics.mainPid, ["content"], function (err, data) {
                            topics.content = data.content;
                            callback(null);
                        });
    
                    }
    
                function getRecentTopics(category, callback) {
                    categories.getCategoryTopics(category.cid, 0, parseInt(category.numRecentReplies, 10), uid, function (err, data) {
                        var topics = data.topics;
                        category.topics = topics;
                        category.topic_count = topics.length;
    
                        async.each(topics, getMainPost, function (err) {
                            callback(null);
                        });
    
                    });
                }
    
                async.each(categoryData, getRecentTopics, function (err) {
                    next(err, categoryData);
                });
    


Suggested Topics


  • 0 Votes
    3 Posts
    242 Views
  • 0 Votes
    8 Posts
    471 Views
  • 0 Votes
    1 Posts
    861 Views
  • 0 Votes
    4 Posts
    1928 Views
  • 5 Votes
    45 Posts
    16010 Views