Skip to content

Instantly share code, notes, and snippets.

@PeteMichaud
Created September 7, 2013 17:23
Show Gist options
  • Select an option

  • Save PeteMichaud/6477449 to your computer and use it in GitHub Desktop.

Select an option

Save PeteMichaud/6477449 to your computer and use it in GitHub Desktop.

Revisions

  1. PeteMichaud created this gist Sep 7, 2013.
    26 changes: 26 additions & 0 deletions jekyll_import_converter.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    require 'html2markdown' #gem install html2markdown

    dirs = %w(_pages _posts)

    class String
    def word_wrap(line_width = 120)
    self.split("\n").collect do |line|
    line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
    end * "\n"
    end
    end

    def md(file_name)
    file_name.chomp(File.extname(file_name)) + '.md'
    end

    dirs.each do |dir|
    Dir.open(dir) do |d_handle|
    d_handle.reject{ |f| f == '.' || f == '..' }.each do |file_name|

    content = HTMLPage.new(:contents => File.read("#{dir}/#{file_name}"))
    File.write("#{dir}/#{md(file_name)}", content.markdown.word_wrap)

    end
    end
    end