Skip to content

dandv/discourse-post-process

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Process Discourse posts

This Node.js script uses the Discourse API (via the discourse-api module) to process posts in a Discourse forum. It will:

  • apply a set of regexp-based transformations, such as replacing BBCode tags with Markdown, e.g. [hr] with ------
  • warn about patterns that may cause rendering problems, such as unconverted [list]s or newlines in nested quotes.

I've tested the script manually on 400+ posts migrated from MyBB and am quite satisfied with it.

It can also delete users from a list of filters, which is useful to clean up spammers coming from a given domain or matching some email address pattern.

Dependencies

The script uses ES6 features and thus requires Node v4 or later.

Usage

Simply clone this repo and edit the script to select which transformations and warning checks you'd like to be run.

Note on topic activity

Note that processing posts will generate (faux) activity in their topic. If the script fixes issues in a bunch of old posts, those will show up at the top of the forum's homepage, even though no "real" activity has occurred.

The recommended way to deal with this is to either,

  • process all posts ASAP, at once, before actual users come visit the site
  • process a small number of posts at large intervals, e.g. 5 posts per day, for many days on end.

Fixing quotes

If you've migrated from MyBB before Discourse accepted my pull request to fix inline quoting for MyBB imports, quote lines appear raw. The script can fix these if you've already imported from MyBB (and likely from other forum engines). Here's what you need to do:

  1. Obtain an array in the format "<old_id>": "post:<post_num>, topic:<topic_id>" by running an import script patched to puts "\nXXX \"#{quoted_post_id}\": \"post:#{post.post_number}, topic:#{post.topic_id}\"" and filtering for lines starting with XXX. For example for the MyBB importer, you can add that line after this line.
  2. Make sure the array is in a valid JSON file.
  3. Name that file post_id_mapping.json. The script will read it.

Fixing colors

BBCode supports [color] tags. Discourse does not, but there's a plugin for that called bbcode-color. While this script could re-save posts that contain [color] tags, it's better to install that plugin and run rake posts:rebake to make sure existing posts with color tags are rendered properly. This way, no extra revisions will be created just for interpreting the [color] tags.

License

MIT

About

Update/alter/modify/process Discourse posts, e.g. do search and replace, such as after a migration

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published