FEATURE: option to use ruby-bbcode-to-md to convert bbcode to markdown before importing posts

This commit is contained in:
Neil Lalonde 2014-07-02 16:50:44 -04:00
parent 462dcadd01
commit 67b9fec204
1 changed files with 18 additions and 0 deletions

View File

@ -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 module ImportScripts; end
class ImportScripts::Base class ImportScripts::Base
@ -5,6 +18,7 @@ class ImportScripts::Base
def initialize def initialize
require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
@bbcode_to_md = true if ARGV.include?('bbcode-to-md')
@existing_users = {} @existing_users = {}
@failed_users = [] @failed_users = []
@categories = {} @categories = {}
@ -253,6 +267,10 @@ class ImportScripts::Base
user = User.find(opts[:user_id]) user = User.find(opts[:user_id])
opts = opts.merge(skip_validations: true) 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) PostCreator.create(user, opts)
end end