Skip to content

Instantly share code, notes, and snippets.

@mizzy
Created October 29, 2011 11:34
Show Gist options
  • Save mizzy/1324352 to your computer and use it in GitHub Desktop.
Save mizzy/1324352 to your computer and use it in GitHub Desktop.
Convert typo blog contents to jekyll posts
require "rubygems"
require "active_record"
ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:host => "192.168.10.12",
:user => "root",
:password => "root",
:database => "typo",
:encoding => "utf8"
)
class Content < ActiveRecord::Base
Content.inheritance_column = 'foo'
end
contents = Content.all
contents.each do |content|
dt = content.published_at
date = sprintf("%04s-%02d-%02d", dt.year, dt.month, dt.day)
datetime = date + sprintf(" %02d:%02d", dt.hour, dt.min)
file = date + "-" + content.id.to_s + ".markdown"
body = <<BODY
---
layout: post
title: "#{content.title}"
date: #{datetime}
comments: true
categories:
---
#{content.body}
BODY
File.open(file, 'w') do |file|
file.write(body)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment