trying to start a plugin, but missing the understanding of how the parts play together and their data formats


  • @baris thanks .. thats what I am trying to do (add the console.log)

    my plug in installed, and 'activated'

    but doesn't seem to be called.
    my plugins.json

    {
    	"id": "nodebb-plugin-moderation_on_links",
    	"url": "https://github.com/sdetweil/nodebb-plugin-moderation_on_links",
    	"library": "./library.js",
    	"hooks": [
    		{
    			"hook": "static:app.load", "method": "init"
    		},
    		{
    			"hook": "filter:admin.header.build", "method": "addAdminNavigation"
    		},
    		{
    			"hook":"filter:post.shouldQueue", "method": "postQueue"
    		}
    	],
    	"staticDirs": {
    		"static": "./static"
    	},
    	"less": [
    		"static/style.less"
    	],
    	"acpScripts": [
    		"static/lib/admin.js"
    	],
    	"templates": "static/templates"
    }
    

    my library.js for the postQueue
    ``
    plugin= {}
    plugin.postQueue = function (postData) {
    try {
    // assume no links, or good links
    // let the post pass on thru
    console.log("postQueue="+JSON.stringify(postData,null,2))
    postData.shouldQueue = false;
    {
    } catch (error) {
    console.error("oops. postQueue error=",error)
    }

    return postData;
    

    };

    module.exports = plugin;
    ...

    should always override the postQueue in this simple test , but doesn't

    i thought I should be able to see this in the logs, when logged on as admin, but don't see it..

    dont see output on browser dev console or terminal window

  • NodeBB Admin

    Is your plugin's init method called? If it is not called there is a problem loading your plugin. Check the startup logs for nodebb.


  • @baris had a syntax error in the index.js.. oops.. not reported..

    node -c index.js

    reported it..

    now my logs work.. (see as admin)

    ugh.. not the raw html..

  • NodeBB Admin

    You can parse the content with

    const mockpost = { content: hookData.data.content };
    await Posts.parsePost(mockPost);
    console.log(mockpost.content);
    

    This will use the active parse plugin, usually nodebb-plugin-markdown to convert content into html.


  • @baris thanks.. where do I find available libraries and their functionality?, and what to import to get 'Posts'..?

    there is a nice sentence about using them, but not how to find a list and what the imports are..

  • NodeBB Admin

    Libraries come from core nodebb, https://github.com/NodeBB/NodeBB/tree/master/src.

    To get the Posts object in your plugin you would add this at the top.

    const Posts = require.main.require('./src/posts');
    

    Then you can use the methods in the Posts object like parsePost.

    Some other ones would be

    const Topics = require.main.require('./src/topics');
    const Categories = require.main.require('./src/categories');
    const Groups = require.main.require('./src/groups');
    /// etc...
    

  • @baris said in trying to start a plugin, but missing the understanding of how the parts play together and their data formats:

    const Posts = require.main.require('./src/posts')

    thanks.. how could I discover that myself?

    nothing talks about the core libs in the creating a plugin section.,.

    just trying to be self sufficient..

  • NodeBB Admin

    You need to be familiar with the nodebb core code at https://github.com/NodeBB/NodeBB/tree/master/src. The libraries are all in those folders for posts, topics, categories, users, groups etc.

    Has a section that mentions how to load core libraries.

    faf797ea-1afb-47b0-adb1-77f6388e0140-image.png


  • @baris thanks.. the 'use require.main.require' is like saying to find a phone number, use the phonebook.

    do I have to read the source for each object to learns its methods?

    user.exists for example from the image

  • NodeBB Admin

    do I have to read the source for each object to learns its methods?

    Yes, you will have to read the source code to see what methods are available.


Suggested Topics

| | | |