From 67b9fec204db8f5b5fe24fa2531f5879fb8fa123 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 2 Jul 2014 16:50:44 -0400 Subject: [PATCH] FEATURE: option to use ruby-bbcode-to-md to convert bbcode to markdown before importing posts --- script/import_scripts/base.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/script/import_scripts/base.rb b/script/import_scripts/base.rb index 1904d8752..baefa0b5e 100644 --- a/script/import_scripts/base.rb +++ b/script/import_scripts/base.rb @@ -1,3 +1,16 @@ +if ARGV.include?('bbcode-to-md') + # Replace (most) bbcode with markdown before creating posts. + # This will dramatically clean up the final posts in Discourse. + # + # In a temp dir: + # + # git clone git@github.com:nlalonde/ruby-bbcode-to-md.git + # cd ruby-bbcode-to-md + # gem build ruby-bbcode-to-md.gemspec + # gem install ruby-bbcode-to-md-0.0.13.gem + require 'ruby-bbcode-to-md' +end + module ImportScripts; end class ImportScripts::Base @@ -5,6 +18,7 @@ class ImportScripts::Base def initialize require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") + @bbcode_to_md = true if ARGV.include?('bbcode-to-md') @existing_users = {} @failed_users = [] @categories = {} @@ -253,6 +267,10 @@ class ImportScripts::Base user = User.find(opts[:user_id]) opts = opts.merge(skip_validations: true) + if @bbcode_to_md + opts[:raw] = opts[:raw].bbcode_to_md rescue opts[:raw] + end + PostCreator.create(user, opts) end