Skip to content

Commit

Permalink
scripts to import to Pages wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
jchris committed Aug 12, 2010
1 parent d738d61 commit accdf31
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
32 changes: 32 additions & 0 deletions bin/md2couchpages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env ruby
require "couchrest"
require "enc/trans/transdb"

target_dir = File.join(File.dirname(__FILE__), '../site/translated/')

db_url = "http://jchris:jchris@localhost:5984/couchdb-wiki"
db = CouchRest.database(db_url)

Dir[File.join(target_dir, "**")].each do |name|

article = open(name).read
next if article.match("system and help pages")
title = File.basename(name, ".md")
puts "saving #{title}"
doc = {
"jquery.couch.attachPrevRev" => true,
"title" => title,
"_id" => title,
"markdown" => article,
"edit_at" => Time.now,
"edit_by" => {
"name" => "moinmoin import"
},
"log" => [{
"note" => "import from http://wiki.apache.org/couchdb/"+title
}]
}
olddoc = db.get(title) rescue nil
doc["_rev"] = olddoc["_rev"] if olddoc
db.save_doc(doc)
end
15 changes: 11 additions & 4 deletions bin/mm2md.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,25 @@ def mm2md(input)
# got the regexp from http://flanders.co.nz/2009/11/08/a-good-url-regular-expression-repost/
{
:regexp => /(?:\s|^)((?#Protocol)(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?#Username:Password)(?:\w+:\w+@)?(?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|\/.,*:=]|%[a-f\d]{2})*)?)(?:\s|$)/,
:replacement => %Q{ <a href="\\1">\\1</a> },
:replacement => %Q{<\\1>},
},


# basic processing of named links
{
:regexp => /\[\[(?:(.*?)\|([^\]]*?))\]\]/,
:replacement => %Q{<a href="\\1">\\2</a>},
:replacement => %Q{\[\\2\]\(\\1\)},
},
# ... and just links
{
:regexp => /\[\[(https?|irc|mailto):\/\/(.*?)\]\]/,
:replacement => %Q{<a href="\\1">\\1</a>},
:replacement => %Q{<\\1>},
},

# MailTo
{
:regexp => /<<MailTo\((.*?)\)>>/,
:replacement => '[\\1](mailto:\\1)'
},

# Table of Contents
Expand Down Expand Up @@ -174,11 +180,12 @@ def mm2md(input)
puts mm2md(input)
else
FileUtils.mkdir_p(target_dir)
# TODO get mm from subdirectories
Dir.glob(File.join(File.dirname(__FILE__),"../wiki/**mm")).each do |file|
target_file = File.join(target_dir, File.basename(file, ".mm")) + ".md"
File.open(target_file, 'w') do |f|
puts "Transcoding #{File.basename(file)}"
f.write("template: page.html\ntitle: #{File.basename(file, ".mm")}\n\n" + mm2md(File.read(file)))
f.write(mm2md(File.read(file)))
end
end
end

0 comments on commit accdf31

Please sign in to comment.