@baris said in "tag list" to choose from?:
Yeah that's correct you would have to do them one by one in the UI. Alternatively if you are going to set all categories to the same 200 tags you can run the below script in your nodebb folder. Update the tags
array to the the tags you wan't to allow. This script would delete all existing tag whitelists for all categories then set all categories to same list of allowed tags.
/* globals require, console, process */
'use strict';
const nconf = require('nconf');
nconf.file({
file: 'config.json',
});
nconf.defaults({
base_dir: __dirname,
views_dir: './build/public/templates',
upload_path: 'public/uploads',
});
var db = require('./src/database');
// update to your own tags
const tags = ['tag1', 'tag2', 'tag3'];
db.init(function (err) {
if (err) {
console.log('NodeBB could not connect to your database. Error: ' + err.message);
process.exit();
}
setCategoryWhitelist(function (err) {
if (err) {
console.error(err);
process.exit();
}
console.log('done');
process.exit();
});
});
async function setCategoryWhitelist(callback) {
const cids = await db.getSortedSetRange('categories:cid', 0, -1);
// delete all existing tags
await db.deleteAll(cids.map(cid => `cid:${cid}:tag:whitelist`));
// set new tag whitelist for all categories
const bulkAdd = [];
cids.forEach((cid) => {
tags.forEach((tag, index) => {
bulkAdd.push([`cid:${cid}:tag:whitelist`, index, tag]);
});
});
await db.sortedSetAddBulk(bulkAdd);
callback();
}
Hi Baris, can we use the same code for tag whitelisting in NodeBB 3.7 ?