Discourse Post Process: A Node.js script that uses the Discourse API to perform search and replace operations on Discourse posts.
The script, introduced by dandv, allows users to apply regular expression-based transformations to posts, including converting BBCode to Markdown, fixing @username mentions, and more. It also warns about potential rendering problems and missing attachments.
dandv has successfully tested the script on over 500 posts and has made it available on GitHub.
featheredtoast has contributed to the project by adding support for phpBB [youtube] tags and proposing a dry-run option.
Users considering running the script on large forums should be aware of potential scaling issues, as experienced by anon36895752, who encountered rate limits when processing a large number of posts. dandv recommends running the script in batches to avoid breaking too many posts at once.
The script is believed to be compatible with the latest Discourse version, as suggested by pfaffman, who also references a related Meta Discourse thread: Replace a string in all posts.
I’m happy to introduce this simple but powerful Node.js script that uses the Discourse API to mass-modify Discourse posts. It essentially performs a regexp-based search & replace across all posts in a forum.
After migrating a few thousand posts from MyBB to Discourse, there was various little tweaks that needed to be made (fix BBCode → Markdown conversion, re-attach attachments, fix @username mentions when the usernames have changed etc.) I’m not a Ruby coder, and writing a simple Ruby script to post-process posts was non-trivial. Using the Discourse API was much easier.
Features
Apply a set of regexp-based transformations to each post, such as replacing BBCode tags with Markdown ones, e.g. [hr] with ---
Mention as the edit reason all transformations that have been applied
Warn about patterns that may cause rendering problems, such as unconverted [list]s or newlines in nested quotes.
Warn about potentially missing attachments
Detect whether [color=] tags have been used (install the bbcode-color plugin to support colors)
Can you tell me, how tailored is this to MYBB. I’m considering running it on PHPBB imported data. And i’m just wondering if there are any gotcha’s i should watch out for?
I’ve run my script in batches just to make sure it wouldn’t break too many posts at once, and without any rate limits added or disabled. I think the largest batch was 1000 posts or so, but I haven’t run into Discourse limits.