Various conversion scripts from other blogging engines
This commit is contained in:
parent
d8c54fa51a
commit
aba5089283
|
@ -0,0 +1,26 @@
|
||||||
|
module Jekyll
|
||||||
|
module CSV
|
||||||
|
#Reads a csv with title, permalink, body, published_at, and filter.
|
||||||
|
#It creates a post file for each row in the csv
|
||||||
|
def self.process(file = "posts.csv")
|
||||||
|
FileUtils.mkdir_p "_posts"
|
||||||
|
posts = 0
|
||||||
|
FasterCSV.foreach(file) do |row|
|
||||||
|
next if row[0] == "title"
|
||||||
|
posts += 1
|
||||||
|
name = row[3].split(" ")[0]+"-"+row[1]+(row[4] =~ /markdown/ ? ".markdown" : ".textile")
|
||||||
|
File.open("_posts/#{name}", "w") do |f|
|
||||||
|
f.puts <<-HEADER
|
||||||
|
---
|
||||||
|
layout: post
|
||||||
|
title: #{row[0]}
|
||||||
|
---
|
||||||
|
|
||||||
|
HEADER
|
||||||
|
f.puts row[2]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
"Created #{posts} posts!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,24 @@
|
||||||
|
require 'rubygems'
|
||||||
|
require 'fastercsv'
|
||||||
|
require 'fileutils'
|
||||||
|
require File.join(File.dirname(__FILE__),"csv.rb")
|
||||||
|
module Jekyll
|
||||||
|
module Mephisto
|
||||||
|
#Accepts a hash with database config variables, exports mephisto posts into a csv
|
||||||
|
#export PGPASSWORD if you must
|
||||||
|
def self.postgres(c)
|
||||||
|
sql = <<-SQL
|
||||||
|
BEGIN;
|
||||||
|
CREATE TEMP TABLE jekyll AS
|
||||||
|
SELECT title, permalink, body, published_at, filter FROM contents
|
||||||
|
WHERE user_id = 1 AND type = 'Article' ORDER BY published_at;
|
||||||
|
COPY jekyll TO STDOUT WITH CSV HEADER;
|
||||||
|
ROLLBACK;
|
||||||
|
SQL
|
||||||
|
command = %Q(psql -h #{c[:host] || "localhost"} -c "#{sql.strip}" #{c[:database]} #{c[:username]} -o #{c[:filename] || "posts.csv"})
|
||||||
|
puts command
|
||||||
|
`#{command}`
|
||||||
|
CSV.process
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue