• 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

iterate on nodebb posts

Scheduled Pinned Locked Moved Plugin Requests
15 Posts 3 Posters 3.3k 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.
  • B Offline
    B Offline
    bentael Plugin & Theme Dev
    wrote on last edited by bentael
    #6

    @sanatisharif , the import plugin already does that, as long as you have actually completed the import process. You can iterate over all of these records, posts, topics, signatures, etc.. and convert them, either via custom JS or using the built-in HTML-To-Markdown, or BBCode-To-Markdown, or both at the same time.

    The best part is that importer had already save a copy of the original content, so you can run it multiple times, each time as if it was the first.

    0_1449935690691_Screen Shot 2015-12-12 at 10.53.38 AM.png ,

    1 Reply Last reply
    1
  • B Offline
    B Offline
    bentael Plugin & Theme Dev
    wrote on last edited by bentael
    #7

    Now, granted, your plugin https://github.com/sohrabafard/nodebb-plugin-alter-allContent, would be a little different, because it won't require the import plugin, nor any import process to occur.

    @julian I believe @sanatisharif just want to iterate over all posts and topics and do some string operations on them. most likely to fix this, https://github.com/akhoury/nodebb-plugin-import/issues/108

    @sanatisharif , im looking into this today

    1 Reply Last reply
    0
  • B Offline
    B Offline
    bentael Plugin & Theme Dev
    wrote on last edited by
    #8

    i'll fix the utf-8 thingy and we can write your plugin later, but it should be easy.

    S 1 Reply Last reply
    0
  • S Offline
    S Offline
    sanatisharif
    replied to bentael on last edited by
    #9

    @bentael yes I wan't this plugin to fix imported posts, also I can't use "Toggle Post-import-tools" because of this issue:

    Toggle post-import tools Is disabled! · Issue #143 · akhoury/nodebb-plugin-import

    Pre-parse all content with my custom JavaScript and Post-parse all content with my custom JavaScript didn't show any input box when checked or unchecked them. we have this errors on console on home page of this plugin : WebSocket connect...

    favicon

    GitHub (github.com)

    1 Reply Last reply
    0
  • S Offline
    S Offline
    sanatisharif
    wrote on last edited by
    #10

    pre-parse function Syntax:

    content = encoding.convert(content,"windows-1252","utf8").toString().replace(/�/gi,'ف');
    
    1 Reply Last reply
    0
  • B Offline
    B Offline
    bentael Plugin & Theme Dev
    wrote on last edited by
    #11

    @sanatisharif glad to know what worked for you. Can you share a link to your forum, i'd like to test the encoding on various operating systems

    S 1 Reply Last reply
    0
  • S Offline
    S Offline
    sanatisharif
    replied to bentael on last edited by
    #12

    @bentael
    our forum:
    آموزش مجازی آلاء
    Our Association provides for poor students, free and quality education.
    Thank you very much, you saved us!

    1 Reply Last reply
    0
  • S Offline
    S Offline
    sanatisharif
    wrote on last edited by
    #13

    using this plugin - alter all existing content - we can remove all unrecognized bbcode to markdown plugin.

    1 Reply Last reply
    0
  • B Offline
    B Offline
    bentael Plugin & Theme Dev
    wrote on last edited by
    #14

    You can still use the parseBefore function and just select the "don't touch my content" and convert again, you virtually execute any JavaScript you need, as long as your return a string.

    1 Reply Last reply
    0
  • S Offline
    S Offline
    sanatisharif
    wrote on last edited by sanatisharif
    #15

    @bentael I write this run_me.js file and run it with node run_me.js command, that iterate over all nodebb posts and run a JavaScript function on content filed and update it.

    how to efficient it using db.collection('objects').updateMany() ?

    content of run_me.js file:

    var MongoClient = require('mongodb').MongoClient;
    var assert = require('assert');
    var ObjectId = require('mongodb').ObjectID;
    
    //'mongodb://<dbuser>:<dbpassword>@<mongodb host>:<mongodb port>/<dbName>'
    var url = ''; 
    
    var converter = require("bbcode-to-markdown");
    
    var convert = function(str){ // alter it and put your desire JavaScript cods.
            if ( typeof str == 'string' ){
                    str = str.toString().toLowerCase();
                    return converter(str);
            }
            else
                    return str;
    }
    
    var updatePosts = function(db, callback){
       var cursor =db.collection('objects').find( { _key:{ $regex: /post:/i } } );
       cursor.each(function(err, doc) {
          assert.equal(err, null);
    
          if (doc != null ) {
            var newcontent = convert( doc.content );
            db.collection('objects').updateOne({ _key: doc._key }, { $set: { "content": newcontent } });
            console.log("after  update --"+doc._key);
    
          } else {
             callback();
          }
       });
    }
    
    MongoClient.connect(url, function(err, db) {
      assert.equal(null, err);
    
       updatePosts(db, function() {
            db.close();
       });
    
    });
    
    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