spinto-jekyll 0.11.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/History.txt +321 -0
- data/LICENSE +21 -0
- data/README.textile +41 -0
- data/Rakefile +166 -0
- data/bin/jekyll +289 -0
- data/cucumber.yml +1 -0
- data/features/create_sites.feature +112 -0
- data/features/embed_filters.feature +60 -0
- data/features/markdown.feature +30 -0
- data/features/pagination.feature +27 -0
- data/features/permalinks.feature +65 -0
- data/features/post_data.feature +153 -0
- data/features/site_configuration.feature +145 -0
- data/features/site_data.feature +82 -0
- data/features/step_definitions/jekyll_steps.rb +145 -0
- data/features/support/env.rb +19 -0
- data/lib/jekyll.rb +136 -0
- data/lib/jekyll/converter.rb +50 -0
- data/lib/jekyll/converters/identity.rb +22 -0
- data/lib/jekyll/converters/markdown.rb +125 -0
- data/lib/jekyll/converters/textile.rb +50 -0
- data/lib/jekyll/convertible.rb +112 -0
- data/lib/jekyll/core_ext.rb +52 -0
- data/lib/jekyll/errors.rb +6 -0
- data/lib/jekyll/filters.rb +118 -0
- data/lib/jekyll/generator.rb +7 -0
- data/lib/jekyll/generators/pagination.rb +113 -0
- data/lib/jekyll/layout.rb +44 -0
- data/lib/jekyll/migrators/csv.rb +26 -0
- data/lib/jekyll/migrators/drupal.rb +103 -0
- data/lib/jekyll/migrators/enki.rb +49 -0
- data/lib/jekyll/migrators/joomla.rb +53 -0
- data/lib/jekyll/migrators/marley.rb +52 -0
- data/lib/jekyll/migrators/mephisto.rb +84 -0
- data/lib/jekyll/migrators/mt.rb +86 -0
- data/lib/jekyll/migrators/posterous.rb +67 -0
- data/lib/jekyll/migrators/rss.rb +47 -0
- data/lib/jekyll/migrators/textpattern.rb +58 -0
- data/lib/jekyll/migrators/tumblr.rb +195 -0
- data/lib/jekyll/migrators/typo.rb +51 -0
- data/lib/jekyll/migrators/wordpress.rb +294 -0
- data/lib/jekyll/migrators/wordpressdotcom.rb +70 -0
- data/lib/jekyll/page.rb +155 -0
- data/lib/jekyll/plugin.rb +77 -0
- data/lib/jekyll/post.rb +257 -0
- data/lib/jekyll/site.rb +337 -0
- data/lib/jekyll/static_file.rb +72 -0
- data/lib/jekyll/tags/highlight.rb +76 -0
- data/lib/jekyll/tags/include.rb +37 -0
- data/lib/jekyll/tags/post_url.rb +38 -0
- data/lib/spinto-jekyll.rb +3 -0
- data/spinto-jekyll.gemspec +155 -0
- data/test/helper.rb +34 -0
- data/test/source/.htaccess +8 -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-01-27-empty-categories.textile +7 -0
- data/test/source/_posts/2009-01-27-empty-category.textile +7 -0
- data/test/source/_posts/2009-03-12-hash-#1.markdown +6 -0
- data/test/source/_posts/2009-05-18-empty-tag.textile +6 -0
- data/test/source/_posts/2009-05-18-empty-tags.textile +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/_posts/2010-01-08-triple-dash.markdown +5 -0
- data/test/source/_posts/2010-01-09-date-override.textile +7 -0
- data/test/source/_posts/2010-01-09-time-override.textile +7 -0
- data/test/source/_posts/2010-01-09-timezone-override.textile +7 -0
- data/test/source/_posts/2010-01-16-override-data.textile +4 -0
- data/test/source/_posts/2011-04-12-md-extension.md +7 -0
- data/test/source/_posts/2011-04-12-text-extension.text +0 -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/deal.with.dots.html +7 -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 +32 -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 +11 -0
- data/test/test_configuration.rb +29 -0
- data/test/test_core_ext.rb +66 -0
- data/test/test_filters.rb +62 -0
- data/test/test_generated_site.rb +72 -0
- data/test/test_kramdown.rb +23 -0
- data/test/test_page.rb +117 -0
- data/test/test_pager.rb +113 -0
- data/test/test_post.rb +456 -0
- data/test/test_rdiscount.rb +18 -0
- data/test/test_redcarpet.rb +21 -0
- data/test/test_redcloth.rb +86 -0
- data/test/test_site.rb +220 -0
- data/test/test_tags.rb +201 -0
- metadata +336 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
module Jekyll
|
2
|
+
|
3
|
+
class Layout
|
4
|
+
include Convertible
|
5
|
+
|
6
|
+
# Gets the Site object.
|
7
|
+
attr_reader :site
|
8
|
+
|
9
|
+
# Gets/Sets the extension of this layout.
|
10
|
+
attr_accessor :ext
|
11
|
+
|
12
|
+
# Gets/Sets the Hash that holds the metadata for this layout.
|
13
|
+
attr_accessor :data
|
14
|
+
|
15
|
+
# Gets/Sets the content of this layout.
|
16
|
+
attr_accessor :content
|
17
|
+
|
18
|
+
# Initialize a new Layout.
|
19
|
+
#
|
20
|
+
# site - The Site.
|
21
|
+
# base - The String path to the source.
|
22
|
+
# name - The String filename of the post file.
|
23
|
+
def initialize(site, base, name)
|
24
|
+
@site = site
|
25
|
+
@base = base
|
26
|
+
@name = name
|
27
|
+
|
28
|
+
self.data = {}
|
29
|
+
|
30
|
+
self.process(name)
|
31
|
+
self.read_yaml(base, name)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Extract information from the layout filename.
|
35
|
+
#
|
36
|
+
# name - The String filename of the layout file.
|
37
|
+
#
|
38
|
+
# Returns nothing.
|
39
|
+
def process(name)
|
40
|
+
self.ext = File.extname(name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
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,103 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sequel'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
# NOTE: This converter requires Sequel and the MySQL gems.
|
7
|
+
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
|
8
|
+
# installed, running the following commands should work:
|
9
|
+
# $ sudo gem install sequel
|
10
|
+
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
11
|
+
|
12
|
+
module Jekyll
|
13
|
+
module Drupal
|
14
|
+
# Reads a MySQL database via Sequel and creates a post file for each post
|
15
|
+
# in wp_posts that has post_status = 'publish'. This restriction is made
|
16
|
+
# because 'draft' posts are not guaranteed to have valid dates.
|
17
|
+
QUERY = "SELECT n.nid, \
|
18
|
+
n.title, \
|
19
|
+
nr.body, \
|
20
|
+
n.created, \
|
21
|
+
n.status \
|
22
|
+
FROM node AS n, \
|
23
|
+
node_revisions AS nr \
|
24
|
+
WHERE (n.type = 'blog' OR n.type = 'story') \
|
25
|
+
AND n.vid = nr.vid"
|
26
|
+
|
27
|
+
def self.process(dbname, user, pass, host = 'localhost', prefix = '')
|
28
|
+
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
|
29
|
+
|
30
|
+
if prefix != ''
|
31
|
+
QUERY[" node "] = " " + prefix + "node "
|
32
|
+
QUERY[" node_revisions "] = " " + prefix + "node_revisions "
|
33
|
+
end
|
34
|
+
|
35
|
+
FileUtils.mkdir_p "_posts"
|
36
|
+
FileUtils.mkdir_p "_drafts"
|
37
|
+
|
38
|
+
# Create the refresh layout
|
39
|
+
# Change the refresh url if you customized your permalink config
|
40
|
+
File.open("_layouts/refresh.html", "w") do |f|
|
41
|
+
f.puts <<EOF
|
42
|
+
<!DOCTYPE html>
|
43
|
+
<html>
|
44
|
+
<head>
|
45
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
46
|
+
<meta http-equiv="refresh" content="0;url={{ page.refresh_to_post_id }}.html" />
|
47
|
+
</head>
|
48
|
+
</html>
|
49
|
+
EOF
|
50
|
+
end
|
51
|
+
|
52
|
+
db[QUERY].each do |post|
|
53
|
+
# Get required fields and construct Jekyll compatible name
|
54
|
+
node_id = post[:nid]
|
55
|
+
title = post[:title]
|
56
|
+
content = post[:body]
|
57
|
+
created = post[:created]
|
58
|
+
time = Time.at(created)
|
59
|
+
is_published = post[:status] == 1
|
60
|
+
dir = is_published ? "_posts" : "_drafts"
|
61
|
+
slug = title.strip.downcase.gsub(/(&|&)/, ' and ').gsub(/[\s\.\/\\]/, '-').gsub(/[^\w-]/, '').gsub(/[-_]{2,}/, '-').gsub(/^[-_]/, '').gsub(/[-_]$/, '')
|
62
|
+
name = time.strftime("%Y-%m-%d-") + slug + '.md'
|
63
|
+
|
64
|
+
# Get the relevant fields as a hash, delete empty fields and convert
|
65
|
+
# to YAML for the header
|
66
|
+
data = {
|
67
|
+
'layout' => 'post',
|
68
|
+
'title' => title.to_s,
|
69
|
+
'created' => created,
|
70
|
+
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
|
71
|
+
|
72
|
+
# Write out the data and content to file
|
73
|
+
File.open("#{dir}/#{name}", "w") do |f|
|
74
|
+
f.puts data
|
75
|
+
f.puts "---"
|
76
|
+
f.puts content
|
77
|
+
end
|
78
|
+
|
79
|
+
# Make a file to redirect from the old Drupal URL
|
80
|
+
if is_published
|
81
|
+
aliases = db["SELECT dst FROM #{prefix}url_alias WHERE src = ?", "node/#{node_id}"].all
|
82
|
+
|
83
|
+
aliases.push(:dst => "node/#{node_id}")
|
84
|
+
|
85
|
+
aliases.each do |url_alias|
|
86
|
+
FileUtils.mkdir_p url_alias[:dst]
|
87
|
+
File.open("#{url_alias[:dst]}/index.md", "w") do |f|
|
88
|
+
f.puts "---"
|
89
|
+
f.puts "layout: refresh"
|
90
|
+
f.puts "refresh_to_post_id: /#{time.strftime("%Y/%m/%d/") + slug}"
|
91
|
+
f.puts "---"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# TODO: Make dirs & files for nodes of type 'page'
|
98
|
+
# Make refresh pages for these as well
|
99
|
+
|
100
|
+
# TODO: Make refresh dirs & files according to entries in url_alias table
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Adapted by Rodrigo Pinto <rodrigopqn@gmail.com>
|
2
|
+
# Based on typo.rb by Toby DiPasquale
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'sequel'
|
7
|
+
|
8
|
+
module Jekyll
|
9
|
+
module Enki
|
10
|
+
SQL = <<-EOS
|
11
|
+
SELECT p.id,
|
12
|
+
p.title,
|
13
|
+
p.slug,
|
14
|
+
p.body,
|
15
|
+
p.published_at as date,
|
16
|
+
p.cached_tag_list as tags
|
17
|
+
FROM posts p
|
18
|
+
EOS
|
19
|
+
|
20
|
+
# Just working with postgres, but can be easily adapted
|
21
|
+
# to work with both mysql and postgres.
|
22
|
+
def self.process(dbname, user, pass, host = 'localhost')
|
23
|
+
FileUtils.mkdir_p('_posts')
|
24
|
+
db = Sequel.postgres(:database => dbname,
|
25
|
+
:user => user,
|
26
|
+
:password => pass,
|
27
|
+
:host => host,
|
28
|
+
:encoding => 'utf8')
|
29
|
+
|
30
|
+
db[SQL].each do |post|
|
31
|
+
name = [ sprintf("%.04d", post[:date].year),
|
32
|
+
sprintf("%.02d", post[:date].month),
|
33
|
+
sprintf("%.02d", post[:date].day),
|
34
|
+
post[:slug].strip ].join('-')
|
35
|
+
name += '.textile'
|
36
|
+
|
37
|
+
File.open("_posts/#{name}", 'w') do |f|
|
38
|
+
f.puts({ 'layout' => 'post',
|
39
|
+
'title' => post[:title].to_s,
|
40
|
+
'enki_id' => post[:id],
|
41
|
+
'categories' => post[:tags]
|
42
|
+
}.delete_if { |k, v| v.nil? || v == '' }.to_yaml)
|
43
|
+
f.puts '---'
|
44
|
+
f.puts post[:body].delete("\r")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sequel'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
# NOTE: This migrator is made for Joomla 1.5 databases.
|
7
|
+
# NOTE: This converter requires Sequel and the MySQL gems.
|
8
|
+
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
|
9
|
+
# installed, running the following commands should work:
|
10
|
+
# $ sudo gem install sequel
|
11
|
+
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
12
|
+
|
13
|
+
module Jekyll
|
14
|
+
module Joomla
|
15
|
+
def self.process(dbname, user, pass, host = 'localhost', table_prefix = 'jos_', section = '1')
|
16
|
+
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
|
17
|
+
|
18
|
+
FileUtils.mkdir_p("_posts")
|
19
|
+
|
20
|
+
# Reads a MySQL database via Sequel and creates a post file for each
|
21
|
+
# post in wp_posts that has post_status = 'publish'. This restriction is
|
22
|
+
# made because 'draft' posts are not guaranteed to have valid dates.
|
23
|
+
query = "SELECT `title`, `alias`, CONCAT(`introtext`,`fulltext`) as content, `created`, `id` FROM #{table_prefix}content WHERE state = '0' OR state = '1' AND sectionid = '#{section}'"
|
24
|
+
|
25
|
+
db[query].each do |post|
|
26
|
+
# Get required fields and construct Jekyll compatible name.
|
27
|
+
title = post[:title]
|
28
|
+
slug = post[:alias]
|
29
|
+
date = post[:created]
|
30
|
+
content = 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
|
+
'joomla_id' => post[:id],
|
40
|
+
'joomla_url' => post[:alias],
|
41
|
+
'date' => date
|
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
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
module Marley
|
6
|
+
def self.regexp
|
7
|
+
{ :id => /^\d{0,4}-{0,1}(.*)$/,
|
8
|
+
:title => /^#\s*(.*)\s+$/,
|
9
|
+
:title_with_date => /^#\s*(.*)\s+\(([0-9\/]+)\)$/,
|
10
|
+
:published_on => /.*\s+\(([0-9\/]+)\)$/,
|
11
|
+
:perex => /^([^\#\n]+\n)$/,
|
12
|
+
:meta => /^\{\{\n(.*)\}\}\n$/mi # Multiline Regexp
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.process(marley_data_dir)
|
17
|
+
raise ArgumentError, "marley dir #{marley_data_dir} not found" unless File.directory?(marley_data_dir)
|
18
|
+
|
19
|
+
FileUtils.mkdir_p "_posts"
|
20
|
+
|
21
|
+
posts = 0
|
22
|
+
Dir["#{marley_data_dir}/**/*.txt"].each do |f|
|
23
|
+
next unless File.exists?(f)
|
24
|
+
|
25
|
+
#copied over from marley's app/lib/post.rb
|
26
|
+
file_content = File.read(f)
|
27
|
+
meta_content = file_content.slice!( self.regexp[:meta] )
|
28
|
+
body = file_content.sub( self.regexp[:title], '').sub( self.regexp[:perex], '').strip
|
29
|
+
|
30
|
+
title = file_content.scan( self.regexp[:title] ).first.to_s.strip
|
31
|
+
prerex = file_content.scan( self.regexp[:perex] ).first.to_s.strip
|
32
|
+
published_on = DateTime.parse( post[:published_on] ) rescue File.mtime( File.dirname(f) )
|
33
|
+
meta = ( meta_content ) ? YAML::load( meta_content.scan( self.regexp[:meta]).to_s ) : {}
|
34
|
+
meta['title'] = title
|
35
|
+
meta['layout'] = 'post'
|
36
|
+
|
37
|
+
formatted_date = published_on.strftime('%Y-%m-%d')
|
38
|
+
post_name = File.dirname(f).split(%r{/}).last.gsub(/\A\d+-/, '')
|
39
|
+
|
40
|
+
name = "#{formatted_date}-#{post_name}"
|
41
|
+
File.open("_posts/#{name}.markdown", "w") do |f|
|
42
|
+
f.puts meta.to_yaml
|
43
|
+
f.puts "---\n"
|
44
|
+
f.puts "\n#{prerex}\n\n" if prerex
|
45
|
+
f.puts body
|
46
|
+
end
|
47
|
+
posts += 1
|
48
|
+
end
|
49
|
+
"Created #{posts} posts!"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,84 @@
|
|
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
|
+
QUERY = "SELECT id, \
|
40
|
+
permalink, \
|
41
|
+
body, \
|
42
|
+
published_at, \
|
43
|
+
title \
|
44
|
+
FROM contents \
|
45
|
+
WHERE user_id = 1 AND \
|
46
|
+
type = 'Article' AND \
|
47
|
+
published_at IS NOT NULL \
|
48
|
+
ORDER BY published_at"
|
49
|
+
|
50
|
+
def self.process(dbname, user, pass, host = 'localhost')
|
51
|
+
db = Sequel.mysql(dbname, :user => user,
|
52
|
+
:password => pass,
|
53
|
+
:host => host,
|
54
|
+
:encoding => 'utf8')
|
55
|
+
|
56
|
+
FileUtils.mkdir_p "_posts"
|
57
|
+
|
58
|
+
db[QUERY].each do |post|
|
59
|
+
title = post[:title]
|
60
|
+
slug = post[:permalink]
|
61
|
+
date = post[:published_at]
|
62
|
+
content = post[:body]
|
63
|
+
|
64
|
+
# Ideally, this script would determine the post format (markdown,
|
65
|
+
# html, etc) and create files with proper extensions. At this point
|
66
|
+
# it just assumes that markdown will be acceptable.
|
67
|
+
name = [date.year, date.month, date.day, slug].join('-') + ".markdown"
|
68
|
+
|
69
|
+
data = {
|
70
|
+
'layout' => 'post',
|
71
|
+
'title' => title.to_s,
|
72
|
+
'mt_id' => post[:entry_id],
|
73
|
+
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
|
74
|
+
|
75
|
+
File.open("_posts/#{name}", "w") do |f|
|
76
|
+
f.puts data
|
77
|
+
f.puts "---"
|
78
|
+
f.puts content
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,86 @@
|
|
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
|
+
require 'yaml'
|
9
|
+
|
10
|
+
# NOTE: This converter requires Sequel and the MySQL gems.
|
11
|
+
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
|
12
|
+
# installed, running the following commands should work:
|
13
|
+
# $ sudo gem install sequel
|
14
|
+
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
15
|
+
|
16
|
+
module Jekyll
|
17
|
+
module MT
|
18
|
+
# This query will pull blog posts from all entries across all blogs. If
|
19
|
+
# you've got unpublished, deleted or otherwise hidden posts please sift
|
20
|
+
# through the created posts to make sure nothing is accidently published.
|
21
|
+
QUERY = "SELECT entry_id, \
|
22
|
+
entry_basename, \
|
23
|
+
entry_text, \
|
24
|
+
entry_text_more, \
|
25
|
+
entry_authored_on, \
|
26
|
+
entry_title, \
|
27
|
+
entry_convert_breaks \
|
28
|
+
FROM mt_entry"
|
29
|
+
|
30
|
+
def self.process(dbname, user, pass, host = 'localhost')
|
31
|
+
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
|
32
|
+
|
33
|
+
FileUtils.mkdir_p "_posts"
|
34
|
+
|
35
|
+
db[QUERY].each do |post|
|
36
|
+
title = post[:entry_title]
|
37
|
+
slug = post[:entry_basename].gsub(/_/, '-')
|
38
|
+
date = post[:entry_authored_on]
|
39
|
+
content = post[:entry_text]
|
40
|
+
more_content = post[:entry_text_more]
|
41
|
+
entry_convert_breaks = post[:entry_convert_breaks]
|
42
|
+
|
43
|
+
# Be sure to include the body and extended body.
|
44
|
+
if more_content != nil
|
45
|
+
content = content + " \n" + more_content
|
46
|
+
end
|
47
|
+
|
48
|
+
# Ideally, this script would determine the post format (markdown,
|
49
|
+
# html, etc) and create files with proper extensions. At this point
|
50
|
+
# it just assumes that markdown will be acceptable.
|
51
|
+
name = [date.year, date.month, date.day, slug].join('-') + '.' +
|
52
|
+
self.suffix(entry_convert_breaks)
|
53
|
+
|
54
|
+
data = {
|
55
|
+
'layout' => 'post',
|
56
|
+
'title' => title.to_s,
|
57
|
+
'mt_id' => post[:entry_id],
|
58
|
+
'date' => date
|
59
|
+
}.delete_if { |k,v| v.nil? || v == '' }.to_yaml
|
60
|
+
|
61
|
+
File.open("_posts/#{name}", "w") do |f|
|
62
|
+
f.puts data
|
63
|
+
f.puts "---"
|
64
|
+
f.puts content
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.suffix(entry_type)
|
70
|
+
if entry_type.nil? || entry_type.include?("markdown")
|
71
|
+
# The markdown plugin I have saves this as
|
72
|
+
# "markdown_with_smarty_pants", so I just look for "markdown".
|
73
|
+
"markdown"
|
74
|
+
elsif entry_type.include?("textile")
|
75
|
+
# This is saved as "textile_2" on my installation of MT 5.1.
|
76
|
+
"textile"
|
77
|
+
elsif entry_type == "0" || entry_type.include?("richtext")
|
78
|
+
# Richtext looks to me like it's saved as HTML, so I include it here.
|
79
|
+
"html"
|
80
|
+
else
|
81
|
+
# Other values might need custom work.
|
82
|
+
entry_type
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|