Section name not being included in breadcrumb

Solved General Discussion
  • Hello,

    My website is: pythonforum.ir and as it's in Persian language, to acknowledge my mean I think it's better to use translators (sorry, I hope this sentence is not offensive, but if it is please pardon me and inform me).

    I have created some Sections like Python 3 and Python 2 which are my issues now. Both sections have their own Q/A and Tutorials forums in which users can create topic.
    But the issue is about breadcrumb that does not include and indicate the Section name.
    If you go to https://pythonforum.ir/category/5/پرسش-و-پاسخ and https://pythonforum.ir/category/8/پرسش-و-پاسخ , you see in the breadcrumb that both have 'Home / Q/A' and if a user creates a topic in Python 2 forum for example, I cannot understand by seeing breadcrumb.

    Is that an issue? Can I solve in Admin settings? I did not find any options for this.

    Thanks in advance

    Solutions
    1- If you just want to fix temporarily (which will be gone by upgrading NodeBB), check posts number 4 and 6. Then restart NodeBB
    2- If you want to create your own plugin or manipulate the changes into the files, see post number 33.
    I recommend post number 33.

  • Bumps 🙂

  • another bump:)

  • From what I can see if a category is marked as a section in the ACP then it won't be used in the breadcrumbs. https://github.com/NodeBB/NodeBB/blob/master/src/controllers/helpers.js#L160

    https://github.com/NodeBB/NodeBB/issues/5717

  • @baris thanks for the hint and reply.
    I changed that line to this:

    if (!data.disabled && data.isSection) {
    

    And now it is working fine.
    Is that right? And would this cause a problem in the future?
    BTW, should I manually modify this file whenever I update/upgrade NodeBB? Am I right?

  • You should actually change it to

    if (!data.disabled) {

    So all categories are used in the breadcrumbs whether they are sections or not.

  • @baris I did this first and when I restart nodebb, my forum does not work. When I revert it back, it works again.
    Anything wrong I did?

  • That could be due to a loop in your category hierarchy, that code is in a while loop and if a category is a parent and child of another category by mistake it will never exit that loop.

    Make sure your category tree doesn't have any loops.

  • @baris that was fine and nothing was wrong with hierarchy.
    It seemed it took some time to affect the changes. Now it's as you wrote down, and my forum is working.
    The issue is solved, thanks.

  • Hello again and sorry for bumping up this old topic.

    The solution of this topic works fine until you do not decide to update/upgrade your NodeBB, because the new file overwrites the modified one so that the changes are reverted back.
    Are there any solutions so that whenever I update/upgrade my forum, the changes are not back?

  • @inna in a plugin/theme you could overwrite that function

    // library.js
    
    const helpers = require.main.require('./src/controllers/helpers');
    
    helpers.buildCategoryBreadcrumbs = // copy of function from core with your modifications
    
  • @pitaj Thanks, but pardon for being unable to get your mean. I added that function to my library.js theme file, but I have some issues.
    This is my /some_path/node_modules/nodebb-theme-persona/library.js:

    'use strict';
    
    const helpers = require.main.require('./src/controllers/helpers');
    helpers.buildCategoryBreadcrumbs = async function (cid) {
            const breadcrumbs = [];
    
            while (parseInt(cid, 10)) {
                    /* eslint-disable no-await-in-loop */
                    const data = await categories.getCategoryFields(cid, ['name', 'slug', 'parentCid', 'disabled', 'isSection']);
                    if (!data.disabled) {
                            breadcrumbs.unshift({
                                    text: String(data.name),
                                    url: `${relative_path}/category/${data.slug}`,
                                    cid: cid,
                            });
                    }
                    cid = data.parentCid;
                                    }
                    if (meta.config.homePageRoute && meta.config.homePageRoute !== 'categories') {
                            breadcrumbs.unshift({
                                    text: '[[global:header.categories]]',
                                    url: `${relative_path}/categories`,
                            });
                    }
    
                    breadcrumbs.unshift({
                            text: '[[global:home]]',
                            url: `${relative_path}/`,
                    });
    
            return breadcrumbs;
    };
    

    These are the first lines of this file. When I restart NodeBB, this is the error I get in the log:

    error: /category/5/%D9%BE%D8%B1%D8%B3%D8%B4-%D9%88-%D9%BE%D8%A7%D8%B3%D8%AE
    ReferenceError: categories is not defined
        at Object.helpers.buildCategoryBreadcrumbs (/some_path/node_modules/nodebb-theme-persona/library.js:9:33)
        at buildBreadcrumbs (/some_path/src/controllers/category.js:140:31)
        at categoryController.get (/some_path/src/controllers/category.js:98:8)
    

    I tried the const helpers = require.main.require('./src/controllers/helpers'); part with absolute path, relative path, both with .js extension and without it, but that does not differ.
    I also tried adding this part at the end of this file but still I get the same error.

    Would you please help me where's the issue? is that correct at all that I'm editing my theme file?
    Can I create a plugin only for doing such things? Is that good?

    Thanks in advance

  • @inna yeah I recommend doing this in a custom plugin or theme, rather than editing the persona files directly.

    Anyways, you'll need to import categories and meta as well like so:

    const categories = require.main.require('./src/categories');
    const meta = require.main.require('./src/meta');
    

    Everything else looks right

  • @pitaj Thanks, but it seems my custom function is not being executed because I do not see any changes after restarting NodeBB.

  • @inna you can try putting a console.log call in there to see whether it's executing. Is it still in the persona file?

  • @pitaj Thanks, I have added console.log(helpers) to library.js file after the function is closed, but when I reload the page I see nothing in console tab.

  • @inna you'd want to put console.log(breadcrumbs) right before the return at the end of the function. If you put it outside the function it will only execute once at startup

  • @pitaj I tried that, but I see nothing in console tab. I tried commenting and uncommenting console.log code to see if it changes, but nothing changes in both cases.
    I have attached the contents of library.js file and console tab.

    Is library.js the correct file I'm trying to edit? Does this file execute in every single page? I mean is that the correct file? I'm asking to ensure whether I'm trying right or not.

    library-js.png console.png

  • @inna that's the right file. Can you look at your startup logs? I bet there's an error on startup caused by you having const meta at the top and later var meta redeclared. This will prevent the plugin from being loaded

  • @pitaj this is it:

    2021-03-04T17:05:46.584Z [4567/600] - error: /some_path/node_modules/nodebb-theme-persona/library.js:37
    var meta = require.main.require('./src/meta');
        ^
    
    SyntaxError: Identifier 'meta' has already been declared
        at Module._compile (internal/modules/cjs/loader.js:723:23)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
        at Module.load (internal/modules/cjs/loader.js:653:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
        at Function.Module._load (internal/modules/cjs/loader.js:585:3)
        at Module.require (internal/modules/cjs/loader.js:692:17)
        at require (internal/modules/cjs/helpers.js:25:18)
        at Object.Plugins.requireLibrary (/some_path/src/plugins/index.js:60:38)
        at registerHooks (/some_path/src/plugins/load.js:159:13)
        at Plugins.loadPlugin (/some_path/src/plugins/load.js:122:4)
    

Suggested Topics


  • 0 Votes
    4 Posts
    136 Views

    @DanAdair It's very slight, but those are different fonts. You can tell because of the tail in the g and the shape of the b.

    I think we updated the fonts so that they're not Poppins anymore? (or maybe we updated them to be Poppins). That doesn't look like the Harmony theme, though.

  • Add to NodeBB sections

    General Discussion
    0 Votes
    11 Posts
    3k Views
  • Topic names broken!!!

    General Discussion
    1 Votes
    3 Posts
    667 Views

    Update nodebb-plugin-rainbows, it should work now.

  • User sections?

    General Discussion
    0 Votes
    2 Posts
    706 Views

    no

  • 0 Votes
    16 Posts
    6k Views

    @Joykiller Not sure if you're around anymore but I thought I'd respond anyway.

    The problem with maintaining a plugin and theme directory is the maintenance aspect. We simply don't have the time to make sure everything is compatible, especially since every plugin created is a community contribution.

    So we automate. We rely on plugin developers to report plugin compatibility, and serve only those plugins that are marked compatible. There is one downside, however, and that is plugins will quickly disappear in successive revisions of NodeBB unless the authors keep them up to date.

    So there's definitely space for crowdsourcing as well. If a plugin is not marked compatible by the developer directly, multiple reports of compatibility by the plugin users should also count, and if enough votes come in, then the plugin should automatically be reintroduced.

    ☝ that part isn't in yet, but it's on the wish list.