iterate on nodebb posts
-
@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.
,
-
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
-
i'll fix the utf-8 thingy and we can write your plugin later, but it should be easy.
-
@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...
GitHub (github.com)
-
pre-parse function Syntax:
content = encoding.convert(content,"windows-1252","utf8").toString().replace(/�/gi,'ف');
-
@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
-
@bentael
our forum:
آموزش مجازی آلاء
Our Association provides for poor students, free and quality education.
Thank you very much, you saved us! -
using this plugin - alter all existing content - we can remove all unrecognized bbcode to markdown plugin.
-
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.
-
@bentael I write this
run_me.js
file and run it withnode run_me.js
command, that iterate over all nodebb posts and run a JavaScript function oncontent
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(); }); });