Trac Wiki to GitHub Wiki
Some TLC is still needed on each output page, but better than doing it all by hand.
Project lives here: github.com/seven1m/trac_wiki_to_github
1 2 #!/usr/bin/env ruby 3 4 TRAC_DB_PATH = 'trac.db' 5 OUT_PATH = 'wiki' 6 GITHUB_WIKI_URL = '/seven1m/onebody/wikis/' 7 8 require 'sqlite3' 9 10 db = SQLite3::Database.new(TRAC_DB_PATH) 11 pages = db.execute('select name, text from wiki w2 where version = (select max(version) from wiki where name = w2.name);') 12 13 pages.each do |title, body| 14 File.open(File.join(OUT_PATH, title.gsub(/\s/, '')), 'w') do |file| 15 body.gsub!(/\{\{\{([^\n]+?)\}\}\}/, '<code>\1</' + 'code>') 16 body.gsub!(/\{\{\{(.+?)\}\}\}/m, '<pre><code>\1</' + 'code></pre>') 17 body.gsub!(/====\s(.+?)\s====/, 'h4. \1') 18 body.gsub!(/===\s(.+?)\s===/, 'h3. \1') 19 body.gsub!(/==\s(.+?)\s==/, 'h2. \1') 20 body.gsub!(/=\s(.+?)\s=[\s\n]*/, '') 21 body.gsub!(/\[(http[^\s\[\]]+)\s([^\[\]]+)\]/, '"\2":\1') 22 body.gsub!(/\[([^\s]+)\s(.+)\]/, '"\2":' + GITHUB_WIKI_URL + '\1') 23 body.gsub!(/([^"\/\!])(([A-Z][a-z0-9]+){2,})/, '\1[[\2]]') 24 body.gsub!(/\!(([A-Z][a-z0-9]+){2,})/, '\1') 25 body.gsub!(/'''(.+)'''/, '*\1*') 26 body.gsub!(/''(.+)''/, '_\1_') 27 body.gsub!(/^\s\*/, '*') 28 body.gsub!(/^\s\d\./, '#') 29 file.write(body) 30 end 31 end