Add a working Mephisto / MySQL converter
This commit is contained in:
parent
94c06d0100
commit
a0da1249a3
|
@ -1,7 +1,19 @@
|
||||||
|
# Quickly hacked together my Michael Ivey
|
||||||
|
# Based on mt.rb by Nick Gerakines, open source and publically
|
||||||
|
# available under the MIT license. Use this module at your own risk.
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
|
require 'sequel'
|
||||||
require 'fastercsv'
|
require 'fastercsv'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require File.join(File.dirname(__FILE__),"csv.rb")
|
require File.join(File.dirname(__FILE__),"csv.rb")
|
||||||
|
|
||||||
|
# NOTE: This converter requires Sequel and the MySQL gems.
|
||||||
|
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
|
||||||
|
# installed, running the following commands should work:
|
||||||
|
# $ sudo gem install sequel
|
||||||
|
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
||||||
|
|
||||||
module Jekyll
|
module Jekyll
|
||||||
module Mephisto
|
module Mephisto
|
||||||
#Accepts a hash with database config variables, exports mephisto posts into a csv
|
#Accepts a hash with database config variables, exports mephisto posts into a csv
|
||||||
|
@ -20,5 +32,48 @@ module Jekyll
|
||||||
`#{command}`
|
`#{command}`
|
||||||
CSV.process
|
CSV.process
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This query will pull blog posts from all entries across all blogs. If
|
||||||
|
# you've got unpublished, deleted or otherwise hidden posts please sift
|
||||||
|
# through the created posts to make sure nothing is accidently published.
|
||||||
|
|
||||||
|
QUERY = "SELECT id, permalink, body, published_at, title FROM contents WHERE user_id = 1 AND type = 'Article' AND published_at IS NOT NULL ORDER BY published_at"
|
||||||
|
|
||||||
|
def self.process(dbname, user, pass, host = 'localhost')
|
||||||
|
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
|
||||||
|
|
||||||
|
FileUtils.mkdir_p "_posts"
|
||||||
|
|
||||||
|
db[QUERY].each do |post|
|
||||||
|
title = post[:title]
|
||||||
|
slug = post[:permalink]
|
||||||
|
date = post[:published_at]
|
||||||
|
content = post[:body]
|
||||||
|
# more_content = ''
|
||||||
|
|
||||||
|
# Be sure to include the body and extended body.
|
||||||
|
# if more_content != nil
|
||||||
|
# content = content + " \n" + more_content
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Ideally, this script would determine the post format (markdown, html
|
||||||
|
# , etc) and create files with proper extensions. At this point it
|
||||||
|
# just assumes that markdown will be acceptable.
|
||||||
|
name = [date.year, date.month, date.day, slug].join('-') + ".markdown"
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'layout' => 'post',
|
||||||
|
'title' => title.to_s,
|
||||||
|
'mt_id' => post[:entry_id],
|
||||||
|
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
|
||||||
|
|
||||||
|
File.open("_posts/#{name}", "w") do |f|
|
||||||
|
f.puts data
|
||||||
|
f.puts "---"
|
||||||
|
f.puts content
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue