• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Creating tags from file?

Scheduled Pinned Locked Moved General Discussion
5 Posts 3 Posters 238 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NodeHam
    wrote on last edited by
    #1

    Is there a way to create tags on the admin site using a cut/paste method, file or some other way? It's really hard to maintain large numbers of tags.

    crazycellsC 1 Reply Last reply
    0
  • crazycellsC Offline
    crazycellsC Offline
    crazycells
    replied to NodeHam on last edited by
    #2

    @NodeHam please check this topic , @baris provided codes to ease this process previously:

    "tag list" to choose from?

    Is it possible to create whitelisted tags for the whole forum , and prevent new tags to be created by regular users? So, everyone can only use tags that are ...

    favicon

    NodeBB Community (community.nodebb.org)

    1 Reply Last reply
    1
  • N Offline
    N Offline
    NodeHam
    wrote on last edited by
    #3

    Thanks. That topic might not be what I'm after.
    From what I read, that sounds like someone wants fixed tags then preventing users from entering them.

    In my application, I need to have a huge list of pre-entered tags but I also want users to enter their own as they post.

    1 Reply Last reply
    0
  • R Offline
    R Offline
    razibal
    wrote on last edited by
    #4

    Here is a slightly modified version of Baris' script that reads a list of tags from a JSON file (tags.json) and creates them

    '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');
    const meta = require('./src/meta');
    const categories = require('./src/categories');
    const cache = require('./src/cache');
    const tags = require('./tags.json');
    db.init(function (err) {
      if (err) {
        console.log('NodeBB could not connect to your database. Error: ' + err.message);
        process.exit();
      }
      setTags(function (err) {
      console.log('setting');
        if (err) {
          console.error(err);
          process.exit();
        }
        console.log('done');
        process.exit();
      });
    });
      async function createEmptyTag(tag) {
        if (!tag) {
          throw new Error('[[error:invalid-tag]]');
        }
        const isMember = await db.isSortedSetMember('tags:topic:count', tag);
        console.log(1, isMember);
        if (!isMember) {
          await db.sortedSetAdd('tags:topic:count', 0, tag);
          cache.del('tags:topic:count');
        }
        const allCids = await categories.getAllCidsFromSet('categories:cid');
        const isMembers = await db.isMemberOfSortedSets(
          allCids.map(cid => `cid:${cid}:tags`), tag
        );
        const bulkAdd = allCids.filter((cid, index) => !isMembers[index])
          .map(cid => ([`cid:${cid}:tags`, 0, tag]));
        await db.sortedSetAddBulk(bulkAdd);
        console.log('added ' + tag);
      };
    
    async function setTags(callback) {
      tags.forEach(async (tag) => {
        console.log('adding tags', tag);
        await createEmptyTag(tag)
      });
          //callback();
      }
    
    1 Reply Last reply
    2
  • N Offline
    N Offline
    NodeHam
    wrote on last edited by
    #5

    That's very kind of you but I'm not sure how to use it? Could you include a little info? I'm sure someone else could benefit from that too.

    Thank you.

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development