Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Rakefile to migrate Bloxsom weblog entries to Jekyll
require 'pathname'
task :bloxsom, [:post_dir, :dest_dir] do |t, args|
Dir.glob(File.join(args[:post_dir], "**/*.txt")).each do |path|
time_stamp = File.stat(path).mtime
relative_path = Pathname.new(path).relative_path_from(Pathname.new(args[:post_dir]))
tags = File.dirname(relative_path).split('/')
tags.delete('.')
content = File.readlines(path)
title = content[0].chomp
puts "#{title}, #{time_stamp.strftime('%Y-%m-%d %H:%M:%S')}, [#{tags.join(', ')}]"
jekyll_file = "#{time_stamp.strftime('%Y-%m-%d-')}#{title.gsub(/\W/, '-')}".gsub(/-+/,'-').chomp('-')
jekyll_file = jekyll_file + '.markdown'
jekyll_path = File.join(args[:dest_dir], jekyll_file)
File.open(jekyll_path, 'w') do |file|
file.write("---\n")
file.write("layout: post\n")
file.write("title: \"#{title}\"\n")
file.write("date: #{time_stamp.strftime('%Y-%m-%d %H:%M:%S')}\n")
file.write("categories: #{tags.join(' ')}\n")
file.write("---\n")
content[1..-1].each {|line| file.write(line)}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment