Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# Author: Stephane Busso based Toby DiPasquale <> Jekyll import and other disqus import
require 'fileutils'
require 'rubygems'
require 'sequel'
require 'rake'
namespace :import
desc "import posts"
task :post do
# this SQL *should* work for both MySQL and PostgreSQL, but I haven't
db = Sequel.postgres dbname, :user => user, :password => pass, :host => host
SQL = <<-EOS
SELECT as id,
c.title as title,
c.permalink as slug,
c.body as body,
c.published_at as date,
c.state as state,
c.keywords as keywords,
COALESCE(, 'html') as filter
FROM contents c
LEFT OUTER JOIN text_filters tf
ON c.text_filter_id =
db[SQL].each do |post|
next unless post[:state] =~ /Published/
dir = post[:date].strftime('content/blog/%Y/%m/%d/')
FileUtils.mkdir_p dir
name = [ sprintf("%.04d", post[:date].year),
sprintf("%.02d", post[:date].month),
sprintf("%.02d", post[:date].day),
post[:slug].strip ].join('-')
# Can have more than one text filter in this field, but we just want
# the first one for this + name + '.textile', 'w') do |f|
'title' => post[:title].to_s,
'blog_post' => true,
'created_at' => post[:date],
'filter' => ['textile'],
'tags' => post[:keywords].gsub(",","").split(" ").compact
}.delete_if { |k, v| v.nil? || v == '' }.to_yaml)
f.puts '---'
f.puts post[:body].gsub("<typo:code>","<pre>").gsub("</typo:code>", "</pre>").delete("\r")
end # import:post
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment