jberkel-jekyll 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/History.txt +151 -0
- data/README.textile +42 -0
- data/Rakefile +90 -0
- data/VERSION.yml +4 -0
- data/bin/jekyll +168 -0
- data/features/create_sites.feature +46 -0
- data/features/embed_filters.feature +60 -0
- data/features/pagination.feature +40 -0
- data/features/permalinks.feature +65 -0
- data/features/post_data.feature +153 -0
- data/features/site_configuration.feature +63 -0
- data/features/site_data.feature +82 -0
- data/features/step_definitions/jekyll_steps.rb +136 -0
- data/features/support/env.rb +16 -0
- data/jekyll.gemspec +141 -0
- data/lib/jekyll/albino.rb +122 -0
- data/lib/jekyll/converters/csv.rb +26 -0
- data/lib/jekyll/converters/marley.rb +53 -0
- data/lib/jekyll/converters/mephisto.rb +79 -0
- data/lib/jekyll/converters/mt.rb +59 -0
- data/lib/jekyll/converters/textpattern.rb +50 -0
- data/lib/jekyll/converters/typo.rb +49 -0
- data/lib/jekyll/converters/wordpress.rb +54 -0
- data/lib/jekyll/convertible.rb +117 -0
- data/lib/jekyll/core_ext.rb +38 -0
- data/lib/jekyll/filters.rb +51 -0
- data/lib/jekyll/haml_helpers.rb +15 -0
- data/lib/jekyll/layout.rb +37 -0
- data/lib/jekyll/page.rb +112 -0
- data/lib/jekyll/pager.rb +45 -0
- data/lib/jekyll/post.rb +310 -0
- data/lib/jekyll/site.rb +316 -0
- data/lib/jekyll/tags/highlight.rb +56 -0
- data/lib/jekyll/tags/include.rb +31 -0
- data/lib/jekyll.rb +86 -0
- data/test/helper.rb +27 -0
- data/test/source/_includes/sig.markdown +3 -0
- data/test/source/_layouts/default.html +27 -0
- data/test/source/_layouts/simple.html +1 -0
- data/test/source/_posts/2008-02-02-not-published.textile +8 -0
- data/test/source/_posts/2008-02-02-published.textile +8 -0
- data/test/source/_posts/2008-10-18-foo-bar.textile +8 -0
- data/test/source/_posts/2008-11-21-complex.textile +8 -0
- data/test/source/_posts/2008-12-03-permalinked-post.textile +9 -0
- data/test/source/_posts/2008-12-13-include.markdown +8 -0
- data/test/source/_posts/2009-01-27-array-categories.textile +10 -0
- data/test/source/_posts/2009-01-27-categories.textile +7 -0
- data/test/source/_posts/2009-01-27-category.textile +7 -0
- data/test/source/_posts/2009-03-12-hash-#1.markdown +6 -0
- data/test/source/_posts/2009-05-18-tag.textile +6 -0
- data/test/source/_posts/2009-05-18-tags.textile +9 -0
- data/test/source/_posts/2009-06-22-empty-yaml.textile +3 -0
- data/test/source/_posts/2009-06-22-no-yaml.textile +1 -0
- data/test/source/about.html +6 -0
- data/test/source/category/_posts/2008-9-23-categories.textile +6 -0
- data/test/source/contacts.html +5 -0
- data/test/source/css/screen.css +76 -0
- data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
- data/test/source/index.html +22 -0
- data/test/source/sitemap.xml +23 -0
- data/test/source/win/_posts/2009-05-24-yaml-linebreak.markdown +7 -0
- data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
- data/test/suite.rb +9 -0
- data/test/test_configuration.rb +29 -0
- data/test/test_filters.rb +49 -0
- data/test/test_generated_site.rb +40 -0
- data/test/test_page.rb +98 -0
- data/test/test_pager.rb +47 -0
- data/test/test_post.rb +302 -0
- data/test/test_site.rb +85 -0
- data/test/test_tags.rb +116 -0
- metadata +194 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
##
|
2
|
+
# Wrapper for the Pygments command line tool, pygmentize.
|
3
|
+
#
|
4
|
+
# Pygments: http://pygments.org/
|
5
|
+
#
|
6
|
+
# Assumes pygmentize is in the path. If not, set its location
|
7
|
+
# with Albino.bin = '/path/to/pygmentize'
|
8
|
+
#
|
9
|
+
# Use like so:
|
10
|
+
#
|
11
|
+
# @syntaxer = Albino.new('/some/file.rb', :ruby)
|
12
|
+
# puts @syntaxer.colorize
|
13
|
+
#
|
14
|
+
# This'll print out an HTMLized, Ruby-highlighted version
|
15
|
+
# of '/some/file.rb'.
|
16
|
+
#
|
17
|
+
# To use another formatter, pass it as the third argument:
|
18
|
+
#
|
19
|
+
# @syntaxer = Albino.new('/some/file.rb', :ruby, :bbcode)
|
20
|
+
# puts @syntaxer.colorize
|
21
|
+
#
|
22
|
+
# You can also use the #colorize class method:
|
23
|
+
#
|
24
|
+
# puts Albino.colorize('/some/file.rb', :ruby)
|
25
|
+
#
|
26
|
+
# Another also: you get a #to_s, for somewhat nicer use in Rails views.
|
27
|
+
#
|
28
|
+
# ... helper file ...
|
29
|
+
# def highlight(text)
|
30
|
+
# Albino.new(text, :ruby)
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# ... view file ...
|
34
|
+
# <%= highlight text %>
|
35
|
+
#
|
36
|
+
# The default lexer is 'text'. You need to specify a lexer yourself;
|
37
|
+
# because we are using STDIN there is no auto-detect.
|
38
|
+
#
|
39
|
+
# To see all lexers and formatters available, run `pygmentize -L`.
|
40
|
+
#
|
41
|
+
# Chris Wanstrath // chris@ozmm.org
|
42
|
+
# GitHub // http://github.com
|
43
|
+
#
|
44
|
+
require 'open4'
|
45
|
+
|
46
|
+
class Albino
|
47
|
+
@@bin = Rails.development? ? 'pygmentize' : '/usr/bin/pygmentize' rescue 'pygmentize'
|
48
|
+
|
49
|
+
def self.bin=(path)
|
50
|
+
@@bin = path
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.colorize(*args)
|
54
|
+
new(*args).colorize
|
55
|
+
end
|
56
|
+
|
57
|
+
def initialize(target, lexer = :text, format = :html)
|
58
|
+
@target = File.exists?(target) ? File.read(target) : target rescue target
|
59
|
+
@options = { :l => lexer, :f => format, :O => 'encoding=utf-8' }
|
60
|
+
end
|
61
|
+
|
62
|
+
def execute(command)
|
63
|
+
output = ''
|
64
|
+
Open4.popen4(command) do |pid, stdin, stdout, stderr|
|
65
|
+
stdin.puts @target
|
66
|
+
stdin.close
|
67
|
+
output = stdout.read.strip
|
68
|
+
[stdout, stderr].each { |io| io.close }
|
69
|
+
end
|
70
|
+
output
|
71
|
+
end
|
72
|
+
|
73
|
+
def colorize(options = {})
|
74
|
+
html = execute(@@bin + convert_options(options))
|
75
|
+
# Work around an RDiscount bug: http://gist.github.com/97682
|
76
|
+
html.to_s.sub(%r{</pre></div>\Z}, "</pre>\n</div>")
|
77
|
+
end
|
78
|
+
alias_method :to_s, :colorize
|
79
|
+
|
80
|
+
def convert_options(options = {})
|
81
|
+
@options.merge(options).inject('') do |string, (flag, value)|
|
82
|
+
string + " -#{flag} #{value}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
if $0 == __FILE__
|
88
|
+
require 'rubygems'
|
89
|
+
require 'test/spec'
|
90
|
+
require 'mocha'
|
91
|
+
begin require 'redgreen'; rescue LoadError; end
|
92
|
+
|
93
|
+
context "Albino" do
|
94
|
+
setup do
|
95
|
+
@syntaxer = Albino.new(__FILE__, :ruby)
|
96
|
+
end
|
97
|
+
|
98
|
+
specify "defaults to text" do
|
99
|
+
syntaxer = Albino.new(__FILE__)
|
100
|
+
syntaxer.expects(:execute).with('pygmentize -f html -l text').returns(true)
|
101
|
+
syntaxer.colorize
|
102
|
+
end
|
103
|
+
|
104
|
+
specify "accepts options" do
|
105
|
+
@syntaxer.expects(:execute).with('pygmentize -f html -l ruby').returns(true)
|
106
|
+
@syntaxer.colorize
|
107
|
+
end
|
108
|
+
|
109
|
+
specify "works with strings" do
|
110
|
+
syntaxer = Albino.new('class New; end', :ruby)
|
111
|
+
assert_match %r(highlight), syntaxer.colorize
|
112
|
+
end
|
113
|
+
|
114
|
+
specify "aliases to_s" do
|
115
|
+
assert_equal @syntaxer.colorize, @syntaxer.to_s
|
116
|
+
end
|
117
|
+
|
118
|
+
specify "class method colorize" do
|
119
|
+
assert_equal @syntaxer.colorize, Albino.colorize(__FILE__, :ruby)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module CSV
|
3
|
+
#Reads a csv with title, permalink, body, published_at, and filter.
|
4
|
+
#It creates a post file for each row in the csv
|
5
|
+
def self.process(file = "posts.csv")
|
6
|
+
FileUtils.mkdir_p "_posts"
|
7
|
+
posts = 0
|
8
|
+
FasterCSV.foreach(file) do |row|
|
9
|
+
next if row[0] == "title"
|
10
|
+
posts += 1
|
11
|
+
name = row[3].split(" ")[0]+"-"+row[1]+(row[4] =~ /markdown/ ? ".markdown" : ".textile")
|
12
|
+
File.open("_posts/#{name}", "w") do |f|
|
13
|
+
f.puts <<-HEADER
|
14
|
+
---
|
15
|
+
layout: post
|
16
|
+
title: #{row[0]}
|
17
|
+
---
|
18
|
+
|
19
|
+
HEADER
|
20
|
+
f.puts row[2]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
"Created #{posts} posts!"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
module Marley
|
6
|
+
|
7
|
+
def self.regexp
|
8
|
+
{ :id => /^\d{0,4}-{0,1}(.*)$/,
|
9
|
+
:title => /^#\s*(.*)\s+$/,
|
10
|
+
:title_with_date => /^#\s*(.*)\s+\(([0-9\/]+)\)$/,
|
11
|
+
:published_on => /.*\s+\(([0-9\/]+)\)$/,
|
12
|
+
:perex => /^([^\#\n]+\n)$/,
|
13
|
+
:meta => /^\{\{\n(.*)\}\}\n$/mi # Multiline Regexp
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.process(marley_data_dir)
|
18
|
+
raise ArgumentError, "marley dir #{marley_data_dir} not found" unless File.directory?(marley_data_dir)
|
19
|
+
|
20
|
+
FileUtils.mkdir_p "_posts"
|
21
|
+
|
22
|
+
posts = 0
|
23
|
+
Dir["#{marley_data_dir}/**/*.txt"].each do |f|
|
24
|
+
next unless File.exists?(f)
|
25
|
+
|
26
|
+
#copied over from marley's app/lib/post.rb
|
27
|
+
file_content = File.read(f)
|
28
|
+
meta_content = file_content.slice!( self.regexp[:meta] )
|
29
|
+
body = file_content.sub( self.regexp[:title], '').sub( self.regexp[:perex], '').strip
|
30
|
+
|
31
|
+
title = file_content.scan( self.regexp[:title] ).first.to_s.strip
|
32
|
+
prerex = file_content.scan( self.regexp[:perex] ).first.to_s.strip
|
33
|
+
published_on = DateTime.parse( post[:published_on] ) rescue File.mtime( File.dirname(f) )
|
34
|
+
meta = ( meta_content ) ? YAML::load( meta_content.scan( self.regexp[:meta]).to_s ) : {}
|
35
|
+
meta['title'] = title
|
36
|
+
meta['layout'] = 'post'
|
37
|
+
|
38
|
+
formatted_date = published_on.strftime('%Y-%m-%d')
|
39
|
+
post_name = File.dirname(f).split(%r{/}).last.gsub(/\A\d+-/, '')
|
40
|
+
|
41
|
+
name = "#{formatted_date}-#{post_name}"
|
42
|
+
File.open("_posts/#{name}.markdown", "w") do |f|
|
43
|
+
f.puts meta.to_yaml
|
44
|
+
f.puts "---\n"
|
45
|
+
f.puts "\n#{prerex}\n\n" if prerex
|
46
|
+
f.puts body
|
47
|
+
end
|
48
|
+
posts += 1
|
49
|
+
end
|
50
|
+
"Created #{posts} posts!"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Quickly hacked together my Michael Ivey
|
2
|
+
# Based on mt.rb by Nick Gerakines, open source and publically
|
3
|
+
# available under the MIT license. Use this module at your own risk.
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'sequel'
|
7
|
+
require 'fastercsv'
|
8
|
+
require 'fileutils'
|
9
|
+
require File.join(File.dirname(__FILE__),"csv.rb")
|
10
|
+
|
11
|
+
# NOTE: This converter requires Sequel and the MySQL gems.
|
12
|
+
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
|
13
|
+
# installed, running the following commands should work:
|
14
|
+
# $ sudo gem install sequel
|
15
|
+
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
16
|
+
|
17
|
+
module Jekyll
|
18
|
+
module Mephisto
|
19
|
+
#Accepts a hash with database config variables, exports mephisto posts into a csv
|
20
|
+
#export PGPASSWORD if you must
|
21
|
+
def self.postgres(c)
|
22
|
+
sql = <<-SQL
|
23
|
+
BEGIN;
|
24
|
+
CREATE TEMP TABLE jekyll AS
|
25
|
+
SELECT title, permalink, body, published_at, filter FROM contents
|
26
|
+
WHERE user_id = 1 AND type = 'Article' ORDER BY published_at;
|
27
|
+
COPY jekyll TO STDOUT WITH CSV HEADER;
|
28
|
+
ROLLBACK;
|
29
|
+
SQL
|
30
|
+
command = %Q(psql -h #{c[:host] || "localhost"} -c "#{sql.strip}" #{c[:database]} #{c[:username]} -o #{c[:filename] || "posts.csv"})
|
31
|
+
puts command
|
32
|
+
`#{command}`
|
33
|
+
CSV.process
|
34
|
+
end
|
35
|
+
|
36
|
+
# This query will pull blog posts from all entries across all blogs. If
|
37
|
+
# you've got unpublished, deleted or otherwise hidden posts please sift
|
38
|
+
# through the created posts to make sure nothing is accidently published.
|
39
|
+
|
40
|
+
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"
|
41
|
+
|
42
|
+
def self.process(dbname, user, pass, host = 'localhost')
|
43
|
+
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
|
44
|
+
|
45
|
+
FileUtils.mkdir_p "_posts"
|
46
|
+
|
47
|
+
db[QUERY].each do |post|
|
48
|
+
title = post[:title]
|
49
|
+
slug = post[:permalink]
|
50
|
+
date = post[:published_at]
|
51
|
+
content = post[:body]
|
52
|
+
# more_content = ''
|
53
|
+
|
54
|
+
# Be sure to include the body and extended body.
|
55
|
+
# if more_content != nil
|
56
|
+
# content = content + " \n" + more_content
|
57
|
+
# end
|
58
|
+
|
59
|
+
# Ideally, this script would determine the post format (markdown, html
|
60
|
+
# , etc) and create files with proper extensions. At this point it
|
61
|
+
# just assumes that markdown will be acceptable.
|
62
|
+
name = [date.year, date.month, date.day, slug].join('-') + ".markdown"
|
63
|
+
|
64
|
+
data = {
|
65
|
+
'layout' => 'post',
|
66
|
+
'title' => title.to_s,
|
67
|
+
'mt_id' => post[:entry_id],
|
68
|
+
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
|
69
|
+
|
70
|
+
File.open("_posts/#{name}", "w") do |f|
|
71
|
+
f.puts data
|
72
|
+
f.puts "---"
|
73
|
+
f.puts content
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Created by Nick Gerakines, open source and publically available under the
|
2
|
+
# MIT license. Use this module at your own risk.
|
3
|
+
# I'm an Erlang/Perl/C++ guy so please forgive my dirty ruby.
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'sequel'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
# NOTE: This converter requires Sequel and the MySQL gems.
|
10
|
+
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
|
11
|
+
# installed, running the following commands should work:
|
12
|
+
# $ sudo gem install sequel
|
13
|
+
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
14
|
+
|
15
|
+
module Jekyll
|
16
|
+
module MT
|
17
|
+
# This query will pull blog posts from all entries across all blogs. If
|
18
|
+
# you've got unpublished, deleted or otherwise hidden posts please sift
|
19
|
+
# through the created posts to make sure nothing is accidently published.
|
20
|
+
QUERY = "SELECT entry_id, entry_basename, entry_text, entry_text_more, entry_created_on, entry_title FROM mt_entry"
|
21
|
+
|
22
|
+
def self.process(dbname, user, pass, host = 'localhost')
|
23
|
+
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
|
24
|
+
|
25
|
+
FileUtils.mkdir_p "_posts"
|
26
|
+
|
27
|
+
db[QUERY].each do |post|
|
28
|
+
title = post[:entry_title]
|
29
|
+
slug = post[:entry_basename]
|
30
|
+
date = post[:entry_created_on]
|
31
|
+
content = post[:entry_text]
|
32
|
+
more_content = post[:entry_text_more]
|
33
|
+
|
34
|
+
# Be sure to include the body and extended body.
|
35
|
+
if more_content != nil
|
36
|
+
content = content + " \n" + more_content
|
37
|
+
end
|
38
|
+
|
39
|
+
# Ideally, this script would determine the post format (markdown, html
|
40
|
+
# , etc) and create files with proper extensions. At this point it
|
41
|
+
# just assumes that markdown will be acceptable.
|
42
|
+
name = [date.year, date.month, date.day, slug].join('-') + ".markdown"
|
43
|
+
|
44
|
+
data = {
|
45
|
+
'layout' => 'post',
|
46
|
+
'title' => title.to_s,
|
47
|
+
'mt_id' => post[:entry_id],
|
48
|
+
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
|
49
|
+
|
50
|
+
File.open("_posts/#{name}", "w") do |f|
|
51
|
+
f.puts data
|
52
|
+
f.puts "---"
|
53
|
+
f.puts content
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sequel'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
# NOTE: This converter requires Sequel and the MySQL gems.
|
6
|
+
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
|
7
|
+
# installed, running the following commands should work:
|
8
|
+
# $ sudo gem install sequel
|
9
|
+
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
10
|
+
|
11
|
+
module Jekyll
|
12
|
+
module TextPattern
|
13
|
+
# Reads a MySQL database via Sequel and creates a post file for each post.
|
14
|
+
# The only posts selected are those with a status of 4 or 5, which means "live"
|
15
|
+
# and "sticky" respectively.
|
16
|
+
# Other statuses is 1 => draft, 2 => hidden and 3 => pending
|
17
|
+
QUERY = "select Title, url_title, Posted, Body, Keywords from textpattern where Status = '4' or Status = '5'"
|
18
|
+
|
19
|
+
def self.process(dbname, user, pass, host = 'localhost')
|
20
|
+
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
|
21
|
+
|
22
|
+
FileUtils.mkdir_p "_posts"
|
23
|
+
|
24
|
+
db[QUERY].each do |post|
|
25
|
+
# Get required fields and construct Jekyll compatible name
|
26
|
+
title = post[:Title]
|
27
|
+
slug = post[:url_title]
|
28
|
+
date = post[:Posted]
|
29
|
+
content = post[:Body]
|
30
|
+
|
31
|
+
name = [date.strftime("%Y-%m-%d"), slug].join('-') + ".textile"
|
32
|
+
|
33
|
+
# Get the relevant fields as a hash, delete empty fields and convert
|
34
|
+
# to YAML for the header
|
35
|
+
data = {
|
36
|
+
'layout' => 'post',
|
37
|
+
'title' => title.to_s,
|
38
|
+
'tags' => post[:Keywords].split(',')
|
39
|
+
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
|
40
|
+
|
41
|
+
# Write out the data and content to file
|
42
|
+
File.open("_posts/#{name}", "w") do |f|
|
43
|
+
f.puts data
|
44
|
+
f.puts "---"
|
45
|
+
f.puts content
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Author: Toby DiPasquale <toby@cbcg.net>
|
2
|
+
require 'fileutils'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'sequel'
|
5
|
+
|
6
|
+
module Jekyll
|
7
|
+
module Typo
|
8
|
+
# this SQL *should* work for both MySQL and PostgreSQL, but I haven't
|
9
|
+
# tested PostgreSQL yet (as of 2008-12-16)
|
10
|
+
SQL = <<-EOS
|
11
|
+
SELECT c.id id,
|
12
|
+
c.title title,
|
13
|
+
c.permalink slug,
|
14
|
+
c.body body,
|
15
|
+
c.published_at date,
|
16
|
+
c.state state,
|
17
|
+
COALESCE(tf.name, 'html') filter
|
18
|
+
FROM contents c
|
19
|
+
LEFT OUTER JOIN text_filters tf
|
20
|
+
ON c.text_filter_id = tf.id
|
21
|
+
EOS
|
22
|
+
|
23
|
+
def self.process dbname, user, pass, host='localhost'
|
24
|
+
FileUtils.mkdir_p '_posts'
|
25
|
+
db = Sequel.mysql dbname, :user => user, :password => pass, :host => host
|
26
|
+
db[SQL].each do |post|
|
27
|
+
next unless post[:state] =~ /Published/
|
28
|
+
|
29
|
+
name = [ sprintf("%.04d", post[:date].year),
|
30
|
+
sprintf("%.02d", post[:date].month),
|
31
|
+
sprintf("%.02d", post[:date].day),
|
32
|
+
post[:slug].strip ].join('-')
|
33
|
+
# Can have more than one text filter in this field, but we just want
|
34
|
+
# the first one for this
|
35
|
+
name += '.' + post[:filter].split(' ')[0]
|
36
|
+
|
37
|
+
File.open("_posts/#{name}", 'w') do |f|
|
38
|
+
f.puts({ 'layout' => 'post',
|
39
|
+
'title' => post[:title].to_s,
|
40
|
+
'typo_id' => post[:id]
|
41
|
+
}.delete_if { |k, v| v.nil? || v == '' }.to_yaml)
|
42
|
+
f.puts '---'
|
43
|
+
f.puts post[:body].delete("\r")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end # module Typo
|
49
|
+
end # module Jekyll
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sequel'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
# NOTE: This converter requires Sequel and the MySQL gems.
|
6
|
+
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
|
7
|
+
# installed, running the following commands should work:
|
8
|
+
# $ sudo gem install sequel
|
9
|
+
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
10
|
+
|
11
|
+
module Jekyll
|
12
|
+
module WordPress
|
13
|
+
|
14
|
+
# Reads a MySQL database via Sequel and creates a post file for each
|
15
|
+
# post in wp_posts that has post_status = 'publish'.
|
16
|
+
# This restriction is made because 'draft' posts are not guaranteed to
|
17
|
+
# have valid dates.
|
18
|
+
QUERY = "select post_title, post_name, post_date, post_content, post_excerpt, ID, guid from wp_posts where post_status = 'publish' and post_type = 'post'"
|
19
|
+
|
20
|
+
def self.process(dbname, user, pass, host = 'localhost')
|
21
|
+
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
|
22
|
+
|
23
|
+
FileUtils.mkdir_p "_posts"
|
24
|
+
|
25
|
+
db[QUERY].each do |post|
|
26
|
+
# Get required fields and construct Jekyll compatible name
|
27
|
+
title = post[:post_title]
|
28
|
+
slug = post[:post_name]
|
29
|
+
date = post[:post_date]
|
30
|
+
content = post[:post_content]
|
31
|
+
name = "%02d-%02d-%02d-%s.markdown" % [date.year, date.month, date.day,
|
32
|
+
slug]
|
33
|
+
|
34
|
+
# Get the relevant fields as a hash, delete empty fields and convert
|
35
|
+
# to YAML for the header
|
36
|
+
data = {
|
37
|
+
'layout' => 'post',
|
38
|
+
'title' => title.to_s,
|
39
|
+
'excerpt' => post[:post_excerpt].to_s,
|
40
|
+
'wordpress_id' => post[:ID],
|
41
|
+
'wordpress_url' => post[:guid]
|
42
|
+
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
|
43
|
+
|
44
|
+
# Write out the data and content to file
|
45
|
+
File.open("_posts/#{name}", "w") do |f|
|
46
|
+
f.puts data
|
47
|
+
f.puts "---"
|
48
|
+
f.puts content
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# Convertible provides methods for converting a pagelike item
|
2
|
+
# from a certain type of markup into actual content
|
3
|
+
#
|
4
|
+
# Requires
|
5
|
+
# self.site -> Jekyll::Site
|
6
|
+
module Jekyll
|
7
|
+
module Convertible
|
8
|
+
# Return the contents as a string
|
9
|
+
def to_s
|
10
|
+
self.content || ''
|
11
|
+
end
|
12
|
+
|
13
|
+
# Read the YAML frontmatter
|
14
|
+
# +base+ is the String path to the dir containing the file
|
15
|
+
# +name+ is the String filename of the file
|
16
|
+
#
|
17
|
+
# Returns nothing
|
18
|
+
def read_yaml(base, name)
|
19
|
+
self.content = File.read(File.join(base, name))
|
20
|
+
|
21
|
+
self.data ||= {}
|
22
|
+
|
23
|
+
if self.content =~ /^(---\s*\n.*?\n?)(---.*?\n)/m
|
24
|
+
self.content = self.content[($1.size + $2.size)..-1]
|
25
|
+
self.data = self.data.deep_merge(YAML.load($1) || {})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Transform the contents based on the file extension.
|
30
|
+
#
|
31
|
+
# Returns nothing
|
32
|
+
def transform
|
33
|
+
case self.content_type
|
34
|
+
when 'textile'
|
35
|
+
self.ext = ".html"
|
36
|
+
self.content = self.site.textile(self.content)
|
37
|
+
when 'markdown'
|
38
|
+
self.ext = ".html"
|
39
|
+
self.content = self.site.markdown(self.content)
|
40
|
+
when 'haml'
|
41
|
+
self.ext = ".html"
|
42
|
+
# Actually rendered in do_layout.
|
43
|
+
self.content = Haml::Engine.new(self.content, :attr_wrapper => %{"}, :filename=>self.name)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Determine which formatting engine to use based on this convertible's
|
48
|
+
# extension
|
49
|
+
#
|
50
|
+
# Returns one of :textile, :markdown or :unknown
|
51
|
+
def content_type
|
52
|
+
case self.ext[1..-1]
|
53
|
+
when /textile/i
|
54
|
+
return 'textile'
|
55
|
+
when /markdown/i, /mkdn/i, /md/i
|
56
|
+
return 'markdown'
|
57
|
+
when /haml/i
|
58
|
+
return 'haml'
|
59
|
+
end
|
60
|
+
return 'unknown'
|
61
|
+
end
|
62
|
+
|
63
|
+
# Sets up a context for Haml and renders in it. The context has accessors
|
64
|
+
# matching the passed-in hash, e.g. "site", "page" and "content", and has
|
65
|
+
# helper modules mixed in.
|
66
|
+
#
|
67
|
+
# Returns String.
|
68
|
+
def render_haml_in_context(haml_engine, params={})
|
69
|
+
context = ClosedStruct.new(params)
|
70
|
+
context.extend(HamlHelpers)
|
71
|
+
context.extend(::Helpers) if defined?(::Helpers)
|
72
|
+
haml_engine.render(context)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Add any necessary layouts to this convertible document
|
76
|
+
# +layouts+ is a Hash of {"name" => "layout"}
|
77
|
+
# +site_payload+ is the site payload hash
|
78
|
+
#
|
79
|
+
# Returns nothing
|
80
|
+
def do_layout(payload, layouts)
|
81
|
+
info = { :filters => [Jekyll::Filters], :registers => { :site => self.site } }
|
82
|
+
|
83
|
+
# render and transform content (this becomes the final content of the object)
|
84
|
+
payload["content_type"] = self.content_type
|
85
|
+
|
86
|
+
if self.content_type == "haml"
|
87
|
+
self.transform
|
88
|
+
self.content = render_haml_in_context(self.content,
|
89
|
+
:site => self.site,
|
90
|
+
:page => ClosedStruct.new(payload["page"]))
|
91
|
+
else
|
92
|
+
self.content = Liquid::Template.parse(self.content).render(payload, info)
|
93
|
+
self.transform
|
94
|
+
end
|
95
|
+
|
96
|
+
# output keeps track of what will finally be written
|
97
|
+
self.output = self.content
|
98
|
+
|
99
|
+
# recursively render layouts
|
100
|
+
layout = layouts[self.data["layout"]]
|
101
|
+
while layout
|
102
|
+
payload = payload.deep_merge({"content" => self.output, "page" => layout.data})
|
103
|
+
|
104
|
+
if site.config['haml'] && layout.content.is_a?(Haml::Engine)
|
105
|
+
self.output = render_haml_in_context(layout.content,
|
106
|
+
:site => ClosedStruct.new(payload["site"]),
|
107
|
+
:page => ClosedStruct.new(payload["page"]),
|
108
|
+
:content => payload["content"])
|
109
|
+
else
|
110
|
+
self.output = Liquid::Template.parse(layout.content).render(payload, info)
|
111
|
+
end
|
112
|
+
|
113
|
+
layout = layouts[layout.data["layout"]]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Hash
|
2
|
+
# Merges self with another hash, recursively.
|
3
|
+
#
|
4
|
+
# This code was lovingly stolen from some random gem:
|
5
|
+
# http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
|
6
|
+
#
|
7
|
+
# Thanks to whoever made it.
|
8
|
+
def deep_merge(hash)
|
9
|
+
target = dup
|
10
|
+
|
11
|
+
hash.keys.each do |key|
|
12
|
+
if hash[key].is_a? Hash and self[key].is_a? Hash
|
13
|
+
target[key] = target[key].deep_merge(hash[key])
|
14
|
+
next
|
15
|
+
end
|
16
|
+
|
17
|
+
target[key] = hash[key]
|
18
|
+
end
|
19
|
+
|
20
|
+
target
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
require 'ostruct'
|
26
|
+
class ClosedStruct < OpenStruct
|
27
|
+
def method_missing(symbol, *args)
|
28
|
+
raise(NoMethodError, "undefined method `#{symbol}' for #{self}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Thanks, ActiveSupport!
|
33
|
+
class Date
|
34
|
+
# Converts datetime to an appropriate format for use in XML
|
35
|
+
def xmlschema
|
36
|
+
strftime("%Y-%m-%dT%H:%M:%S%Z")
|
37
|
+
end if RUBY_VERSION < '1.9'
|
38
|
+
end
|