SOLVED Section name not being included in breadcrumb

  • Global Moderator Plugin & Theme Dev

    @inna yep so try commenting out that line and restarting


  • @pitaj I've tried to check internal/modules/cjs/loader.js, but this path and this file does not exist.
    I also checked src/plugins/load.js and src/plugins/index.js, but they do not have any meta variable or such thing.

    I've also tried to commenting out them, these index.js and load.js files at given lines but I give errors, because I've been trying to commenting out registerHooks and Plugins.loadPlugin and Object.Plugins.requireLibrary.


  • @inna By the way, as I've here, I've entered some info, but I found something:

    at registerHooks (/some_path/src/plugins/load.js:159:13)
    at Plugins.loadPlugin (/some_path/src/plugins/load.js:122:4)
    

    The issue is Plugins.loadPlugin is in line 159, and registerHooks is in line 122.
    Should I report this to NodeBB Github issues? Is it related to Persona theme? Or just reporting here is enough to check it?

  • Global Moderator Plugin & Theme Dev

    No no no no no. Comment out the line with var meta. The one that shows up at the top of the error message you posted. Make sure you uncomment all of those other things.

    This is not a bug in NodeBB. As the error message clearly says, the variable meta was already declared in that scope in library.js. (As const meta ...)


  • @pitaj I'm really sorry for making this thread long and I appreciate you take your priceless time to me.

    I checked load.js and index.js and they have no lines containing with var meta. They just have const meta = require('../meta');. You can check them in Github repo too:
    https://github.com/NodeBB/NodeBB/blob/master/src/plugins/load.js
    https://github.com/NodeBB/NodeBB/blob/master/src/plugins/index.js

    I intended to comment out lines with var meta, but I found nothing.

  • Global Moderator Plugin & Theme Dev

    @inna

    In the error message

    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');
        ^
    

    You need to edit the same file you've been editing the whole time: /some_path/node_modules/nodebb-theme-persona/library.js

    You need to comment out line 37, the one that starts with var meta as shown in the error message.


  • @pitaj I did this and I get error at line 15:

    error: /category/5/%D9%BE%D8%B1%D8%B3%D8%B4-%D9%88-%D9%BE%D8%A7%D8%B3%D8%AE
    ReferenceError: relative_path is not defined
        at Object.helpers.buildCategoryBreadcrumbs (/some_path/node_modules/nodebb-theme-persona/library.js:15:14)
    

    Error in my forum is:

    relative_path is not defined

  • Global Moderator Plugin & Theme Dev

    @inna okay try adding this below the const meta = ... line:

    const relative_path = meta.config.relative_path;
    

  • @pitaj thanks, it's fine now, but there's an issue in the breadcrumbs links.
    Because my forums names are in Persian, there may some ASCII URLs.
    For example, link https://pythonforum.ir/category/5/ itself is fine, but when I go to it and I check the breadcrumbs links (category 5 is 2 levels up after the main site), its previous category link is https://pythonforum.ir/category/5/undefined/category/3/ and Home link is https://pythonforum.ir/category/5/undefined/ .
    To see this, I remain these changes in my website.
    This is log of Nodebb:

    [ { text: '[[global:home]]', url: 'undefined/' },
      { text: 'پایتون ۳', url: 'undefined/category/3/پایتون', cid: 3 } ]
    [ { text: '[[global:home]]', url: 'undefined/' },
      { text: 'قوانین، اطلاعیه‌ها و اخبار',
        url: 'undefined/category/1/قوانین-اطلاعیه-ها-و-اخبار',
        cid: 1 } ]
    [ { text: '[[global:home]]', url: 'undefined/' },
      { text: 'قوانین، اطلاعیه‌ها و اخبار',
        url: 'undefined/category/1/قوانین-اطلاعیه-ها-و-اخبار',
        cid: 1 } ]
    [ { text: '[[global:home]]', url: 'undefined/' },
      { text: 'پایتون ۳', url: 'undefined/category/3/پایتون', cid: 3 } ]
    

    Also if you remember and told me to add a console.log(breadcrumbs), it's still in the file but there's no output in the console tab.

  • Global Moderator Plugin & Theme Dev

    @inna okay it looks like the solution I gave was incorrect, but at least you aren't getting errors.

    meta.config.relative_path is wrong (which is why you see a bunch of undefined). Try this instead:

    const relative_path = require.main.require('nconf').get('relative_path');
    

  • @pitaj thanks a lot, it works fine:)
    Thanks a lot for helping me.

  • Global Moderator Plugin & Theme Dev

    @inna you're welcome!

    Do you mind posting the final code so others may use it as a reference?

    Also I must recommend you move that code into your own custom plugin, as otherwise you may lose your changes. For instance, when upgrading NodeBB that file is likely to be overwritten.


  • @pitaj Sure, why not:)
    In the path /to_your_nodebb_path/node_modules/nodebb-theme-persona/library.js (or whatever file and path you want to add), after the first line which is 'use strict';, add these lines below the first line:

    const helpers = require.main.require('./src/controllers/helpers');
    const categories = require.main.require('./src/categories');
    const meta = require.main.require('./src/meta');
    const relative_path = require.main.require('nconf').get('relative_path');
    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;
    };
    

    Then comment out line starting with var meta by adding two //:

    //var meta = require.main.require('./src/meta');
    

    Then you can restart by either of these ways:

    • /nodebb_path/nodebb restart
    • service nodebb restart
    • systemctl restart nodebb

    Regarding custom plugin, I'll consider it soon.

Suggested Topics

| |