henrik-jekyll 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +115 -0
- data/README.textile +545 -0
- data/Rakefile +91 -0
- data/VERSION.yml +4 -0
- data/bin/jekyll +140 -0
- data/lib/jekyll/albino.rb +120 -0
- data/lib/jekyll/converters/csv.rb +26 -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 +82 -0
- data/lib/jekyll/core_ext.rb +22 -0
- data/lib/jekyll/filters.rb +43 -0
- data/lib/jekyll/layout.rb +36 -0
- data/lib/jekyll/page.rb +67 -0
- data/lib/jekyll/post.rb +205 -0
- data/lib/jekyll/site.rb +238 -0
- data/lib/jekyll/tags/highlight.rb +56 -0
- data/lib/jekyll/tags/include.rb +31 -0
- data/lib/jekyll.rb +83 -0
- data/test/helper.rb +24 -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/category/_posts/2008-9-23-categories.textile +6 -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/z_category/_posts/2008-9-23-categories.textile +6 -0
- data/test/suite.rb +9 -0
- data/test/test_filters.rb +41 -0
- data/test/test_generated_site.rb +38 -0
- data/test/test_post.rb +145 -0
- data/test/test_site.rb +57 -0
- data/test/test_tags.rb +35 -0
- metadata +163 -0
data/Rakefile
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
begin
|
6
|
+
gem 'jeweler', '>= 0.11.0'
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |s|
|
9
|
+
s.name = "jekyll"
|
10
|
+
s.summary = %Q{Jekyll is a simple, blog aware, static site generator.}
|
11
|
+
s.email = "tom@mojombo.com"
|
12
|
+
s.homepage = "http://github.com/mojombo/jekyll"
|
13
|
+
s.description = "Jekyll is a simple, blog aware, static site generator."
|
14
|
+
s.authors = ["Tom Preston-Werner"]
|
15
|
+
s.rubyforge_project = "jekyll"
|
16
|
+
s.files.exclude 'test/dest'
|
17
|
+
s.test_files.exclude 'test/dest'
|
18
|
+
s.add_dependency('RedCloth', '>= 4.0.4')
|
19
|
+
s.add_dependency('liquid', '>= 1.9.0')
|
20
|
+
s.add_dependency('classifier', '>= 1.3.1')
|
21
|
+
s.add_dependency('maruku', '>= 0.5.9')
|
22
|
+
s.add_dependency('directory_watcher', '>= 1.1.1')
|
23
|
+
s.add_dependency('open4', '>= 0.9.6')
|
24
|
+
end
|
25
|
+
rescue LoadError
|
26
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler --version '>= 0.11.0'"
|
27
|
+
exit(1)
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::TestTask.new do |t|
|
31
|
+
t.libs << 'lib'
|
32
|
+
t.pattern = 'test/**/test_*.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
Rake::RDocTask.new do |rdoc|
|
37
|
+
rdoc.rdoc_dir = 'rdoc'
|
38
|
+
rdoc.title = 'jekyll'
|
39
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
40
|
+
rdoc.rdoc_files.include('README*')
|
41
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
42
|
+
end
|
43
|
+
|
44
|
+
begin
|
45
|
+
require 'rcov/rcovtask'
|
46
|
+
Rcov::RcovTask.new do |t|
|
47
|
+
t.libs << 'test'
|
48
|
+
t.test_files = FileList['test/**/test_*.rb']
|
49
|
+
t.verbose = true
|
50
|
+
end
|
51
|
+
rescue LoadError
|
52
|
+
end
|
53
|
+
|
54
|
+
task :default => [:test, :features]
|
55
|
+
|
56
|
+
# console
|
57
|
+
|
58
|
+
desc "Open an irb session preloaded with this library"
|
59
|
+
task :console do
|
60
|
+
sh "irb -rubygems -I lib -r jekyll.rb"
|
61
|
+
end
|
62
|
+
|
63
|
+
# converters
|
64
|
+
|
65
|
+
namespace :convert do
|
66
|
+
desc "Migrate from mephisto in the current directory"
|
67
|
+
task :mephisto do
|
68
|
+
sh %q(ruby -r './lib/jekyll/converters/mephisto' -e 'Jekyll::Mephisto.postgres(:database => "#{ENV["DB"]}")')
|
69
|
+
end
|
70
|
+
desc "Migrate from Movable Type in the current directory"
|
71
|
+
task :mt do
|
72
|
+
sh %q(ruby -r './lib/jekyll/converters/mt' -e 'Jekyll::MT.process("#{ENV["DB"]}", "#{ENV["USER"]}", "#{ENV["PASS"]}")')
|
73
|
+
end
|
74
|
+
desc "Migrate from Typo in the current directory"
|
75
|
+
task :typo do
|
76
|
+
sh %q(ruby -r './lib/jekyll/converters/typo' -e 'Jekyll::Typo.process("#{ENV["DB"]}", "#{ENV["USER"]}", "#{ENV["PASS"]}")')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
begin
|
81
|
+
require 'cucumber/rake/task'
|
82
|
+
|
83
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
84
|
+
t.cucumber_opts = "--format pretty"
|
85
|
+
end
|
86
|
+
rescue LoadError
|
87
|
+
desc 'Cucumber rake task not available'
|
88
|
+
task :features do
|
89
|
+
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
|
90
|
+
end
|
91
|
+
end
|
data/VERSION.yml
ADDED
data/bin/jekyll
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
4
|
+
|
5
|
+
help = <<HELP
|
6
|
+
Jekyll is a blog-aware, static site generator.
|
7
|
+
|
8
|
+
Basic Command Line Usage:
|
9
|
+
jekyll # . -> ./_site
|
10
|
+
jekyll <path to write generated site> # . -> <path>
|
11
|
+
jekyll <path to source> <path to write generated site> # <path> -> <path>
|
12
|
+
|
13
|
+
Configuration is read from '<source>/_config.yaml' but can be overriden
|
14
|
+
using the following options:
|
15
|
+
|
16
|
+
HELP
|
17
|
+
|
18
|
+
require 'optparse'
|
19
|
+
require 'jekyll'
|
20
|
+
|
21
|
+
exec = {}
|
22
|
+
options = {}
|
23
|
+
opts = OptionParser.new do |opts|
|
24
|
+
opts.banner = help
|
25
|
+
|
26
|
+
opts.on("--auto", "Auto-regenerate") do
|
27
|
+
options['auto'] = true
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on("--no-auto", "No auto-regenerate") do
|
31
|
+
options['auto'] = false
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on("--server [PORT]", "Start web server (default port 4000)") do |port|
|
35
|
+
options['server'] = true
|
36
|
+
options['server_port'] = port unless port.nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("--lsi", "Use LSI for better related posts") do
|
40
|
+
options['lsi'] = true
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on("--pygments", "Use pygments to highlight code") do
|
44
|
+
options['pygments'] = true
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("--rdiscount", "Use rdiscount gem for Markdown") do
|
48
|
+
options['markdown'] = 'rdiscount'
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on("--permalink [TYPE]", "Use 'date' (default) for YYYY/MM/DD") do |style|
|
52
|
+
options['permalink'] = style unless style.nil?
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on("--version", "Display current version") do
|
56
|
+
puts "Jekyll " + Jekyll.version
|
57
|
+
exit 0
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Read command line options into `options` hash
|
62
|
+
opts.parse!
|
63
|
+
|
64
|
+
# Get source and destintation from command line
|
65
|
+
case ARGV.size
|
66
|
+
when 0
|
67
|
+
when 1
|
68
|
+
options['destination'] = ARGV[0]
|
69
|
+
when 2
|
70
|
+
options['source'] = ARGV[0]
|
71
|
+
options['destination'] = ARGV[1]
|
72
|
+
else
|
73
|
+
puts "Invalid options. Run `jekyll --help` for assistance."
|
74
|
+
exit(1)
|
75
|
+
end
|
76
|
+
|
77
|
+
options = Jekyll.configuration(options)
|
78
|
+
|
79
|
+
# Get source and destination directories (possibly set by config file)
|
80
|
+
source = options['source']
|
81
|
+
destination = options['destination']
|
82
|
+
|
83
|
+
# Files to watch
|
84
|
+
def globs(source)
|
85
|
+
Dir.chdir(source) do
|
86
|
+
dirs = Dir['*'].select { |x| File.directory?(x) }
|
87
|
+
dirs -= ['_site']
|
88
|
+
dirs = dirs.map { |x| "#{x}/**/*" }
|
89
|
+
dirs += ['*']
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Create the Site
|
94
|
+
site = Jekyll::Site.new(options)
|
95
|
+
|
96
|
+
# Run the directory watcher for auto-generation, if required
|
97
|
+
if options['auto']
|
98
|
+
require 'directory_watcher'
|
99
|
+
|
100
|
+
puts "Auto-regenerating enabled: #{source} -> #{destination}"
|
101
|
+
|
102
|
+
dw = DirectoryWatcher.new(source)
|
103
|
+
dw.interval = 1
|
104
|
+
dw.glob = globs(source)
|
105
|
+
|
106
|
+
dw.add_observer do |*args|
|
107
|
+
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
108
|
+
puts "[#{t}] regeneration: #{args.size} files changed"
|
109
|
+
site.process
|
110
|
+
end
|
111
|
+
|
112
|
+
dw.start
|
113
|
+
|
114
|
+
unless options['server']
|
115
|
+
loop { sleep 1000 }
|
116
|
+
end
|
117
|
+
else
|
118
|
+
puts "Building site: #{source} -> #{destination}"
|
119
|
+
site.process
|
120
|
+
puts "Successfully generated site: #{source} -> #{destination}"
|
121
|
+
end
|
122
|
+
|
123
|
+
# Run the server on the specified port, if required
|
124
|
+
if options['server']
|
125
|
+
require 'webrick'
|
126
|
+
include WEBrick
|
127
|
+
|
128
|
+
FileUtils.mkdir_p(destination)
|
129
|
+
|
130
|
+
s = HTTPServer.new(
|
131
|
+
:Port => options['server_port'],
|
132
|
+
:DocumentRoot => destination
|
133
|
+
)
|
134
|
+
t = Thread.new {
|
135
|
+
s.start
|
136
|
+
}
|
137
|
+
|
138
|
+
trap("INT") { s.shutdown }
|
139
|
+
t.join()
|
140
|
+
end
|
@@ -0,0 +1,120 @@
|
|
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 }
|
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
|
+
execute @@bin + convert_options(options)
|
75
|
+
end
|
76
|
+
alias_method :to_s, :colorize
|
77
|
+
|
78
|
+
def convert_options(options = {})
|
79
|
+
@options.merge(options).inject('') do |string, (flag, value)|
|
80
|
+
string + " -#{flag} #{value}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
if $0 == __FILE__
|
86
|
+
require 'rubygems'
|
87
|
+
require 'test/spec'
|
88
|
+
require 'mocha'
|
89
|
+
begin require 'redgreen'; rescue LoadError; end
|
90
|
+
|
91
|
+
context "Albino" do
|
92
|
+
setup do
|
93
|
+
@syntaxer = Albino.new(__FILE__, :ruby)
|
94
|
+
end
|
95
|
+
|
96
|
+
specify "defaults to text" do
|
97
|
+
syntaxer = Albino.new(__FILE__)
|
98
|
+
syntaxer.expects(:execute).with('pygmentize -f html -l text').returns(true)
|
99
|
+
syntaxer.colorize
|
100
|
+
end
|
101
|
+
|
102
|
+
specify "accepts options" do
|
103
|
+
@syntaxer.expects(:execute).with('pygmentize -f html -l ruby').returns(true)
|
104
|
+
@syntaxer.colorize
|
105
|
+
end
|
106
|
+
|
107
|
+
specify "works with strings" do
|
108
|
+
syntaxer = Albino.new('class New; end', :ruby)
|
109
|
+
assert_match %r(highlight), syntaxer.colorize
|
110
|
+
end
|
111
|
+
|
112
|
+
specify "aliases to_s" do
|
113
|
+
assert_equal @syntaxer.colorize, @syntaxer.to_s
|
114
|
+
end
|
115
|
+
|
116
|
+
specify "class method colorize" do
|
117
|
+
assert_equal @syntaxer.colorize, Albino.colorize(__FILE__, :ruby)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
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,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
|