@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