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



  • 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..! :persevere:

    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);
                });

Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.