jekyll-import 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jekyll-import.rb +8 -12
- data/lib/jekyll-import/importers/csv.rb +55 -17
- data/lib/jekyll-import/importers/drupal6.rb +6 -1
- data/lib/jekyll-import/importers/drupal7.rb +18 -4
- data/lib/jekyll-import/importers/mt.rb +31 -22
- data/lib/jekyll-import/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 978cb59817a6828ea723eeef82002e9520fb9993
|
4
|
+
data.tar.gz: d193cd60fe7c2c3872a072030e2d08d4d7d42637
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd53d8b869acd8123793c72e261e2a5e4a452a3ea3162783aa5df9af32059c23a37a2fb9e5eb238f91894632fb37558b735660c0257b06b242954443afb5e7dd
|
7
|
+
data.tar.gz: ed999729e91426cd839bb5abd8954c6a3004c78b22a6d3571bc5336d3abd634848ea19726aabef4af8041c0485765b18549a6cc3f225622e0a5d08630c051d3d
|
data/lib/jekyll-import.rb
CHANGED
@@ -9,10 +9,6 @@ require 'jekyll-import/importers'
|
|
9
9
|
require 'jekyll-import/util'
|
10
10
|
|
11
11
|
module JekyllImport
|
12
|
-
def self.logger
|
13
|
-
@logger ||= Jekyll::Stevenson.new
|
14
|
-
end
|
15
|
-
|
16
12
|
# Public: Add the subcommands for each importer
|
17
13
|
#
|
18
14
|
# cmd - the instance of Mercenary::Command from the
|
@@ -39,14 +35,14 @@ module JekyllImport
|
|
39
35
|
begin
|
40
36
|
require gem
|
41
37
|
rescue LoadError
|
42
|
-
logger.error "Whoops! Looks like you need to install '#{gem}' before you can use this importer."
|
43
|
-
logger.error ""
|
44
|
-
logger.error "If you're using bundler:"
|
45
|
-
logger.error " 1. Add 'gem \"#{gem}\"' to your Gemfile"
|
46
|
-
logger.error " 2. Run 'bundle install'"
|
47
|
-
logger.error ""
|
48
|
-
logger.error "If you're not using bundler:"
|
49
|
-
logger.abort_with " 1. Run 'gem install #{gem}'."
|
38
|
+
Jekyll.logger.error "Whoops! Looks like you need to install '#{gem}' before you can use this importer."
|
39
|
+
Jekyll.logger.error ""
|
40
|
+
Jekyll.logger.error "If you're using bundler:"
|
41
|
+
Jekyll.logger.error " 1. Add 'gem \"#{gem}\"' to your Gemfile"
|
42
|
+
Jekyll.logger.error " 2. Run 'bundle install'"
|
43
|
+
Jekyll.logger.error ""
|
44
|
+
Jekyll.logger.error "If you're not using bundler:"
|
45
|
+
Jekyll.logger.abort_with " 1. Run 'gem install #{gem}'."
|
50
46
|
end
|
51
47
|
end
|
52
48
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class CSV < Importer
|
@@ -5,6 +7,7 @@ module JekyllImport
|
|
5
7
|
JekyllImport.require_with_fallback(%w[
|
6
8
|
csv
|
7
9
|
fileutils
|
10
|
+
yaml
|
8
11
|
])
|
9
12
|
end
|
10
13
|
|
@@ -23,34 +26,69 @@ module JekyllImport
|
|
23
26
|
abort "Cannot find the file '#{file}'. Aborting." unless File.file?(file)
|
24
27
|
|
25
28
|
::CSV.foreach(file) do |row|
|
26
|
-
next if row[0] == "title"
|
29
|
+
next if row[0] == "title" # header
|
27
30
|
posts += 1
|
28
|
-
|
29
|
-
write_post(name, row[0], row[2], options)
|
31
|
+
write_post(CSVPost.new(row), options)
|
30
32
|
end
|
31
|
-
"Created #{posts} posts!"
|
33
|
+
Jekyll.logger.info "Created #{posts} posts!"
|
32
34
|
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
class CSVPost
|
37
|
+
attr_reader :title, :permalink, :body, :markup
|
38
|
+
|
39
|
+
MissingDataError = Class.new(RuntimeError)
|
40
|
+
|
41
|
+
# Creates a CSVPost
|
42
|
+
#
|
43
|
+
# row - Array of data, length of 4 or 5 with the columns:
|
44
|
+
#
|
45
|
+
# 1. title
|
46
|
+
# 2. permalink
|
47
|
+
# 3. body
|
48
|
+
# 4. published_at
|
49
|
+
# 5. markup (markdown, textile)
|
50
|
+
def initialize(row)
|
51
|
+
@title = row[0] || missing_data("Post title not present in first column.")
|
52
|
+
@permalink = row[1] || missing_data("Post permalink not present in second column.")
|
53
|
+
@body = row[2] || missing_data("Post body not present in third column.")
|
54
|
+
@published_at = row[3] || missing_data("Post publish date not present in fourth column.")
|
55
|
+
@markup = row[4] || "markdown"
|
56
|
+
end
|
57
|
+
|
58
|
+
def published_at
|
59
|
+
if @published_at && !@published_at.is_a?(DateTime)
|
60
|
+
@published_at = DateTime.parse(@published_at)
|
61
|
+
else
|
62
|
+
@published_at
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def filename
|
67
|
+
"#{published_at.strftime("%Y-%m-%d")}-#{File.basename(permalink, ".*")}.#{markup}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def missing_data(message)
|
71
|
+
raise MissingDataError, message
|
38
72
|
end
|
39
73
|
end
|
40
74
|
|
41
|
-
def self.
|
42
|
-
|
75
|
+
def self.write_post(post, options = {})
|
76
|
+
File.open(File.join("_posts", post.filename), "w") do |f|
|
77
|
+
write_frontmatter(f, post, options)
|
78
|
+
f.puts post.body
|
79
|
+
end
|
43
80
|
end
|
44
81
|
|
45
|
-
def self.write_frontmatter(f,
|
82
|
+
def self.write_frontmatter(f, post, options)
|
46
83
|
no_frontmatter = options.fetch('no-front-matter', false)
|
47
84
|
unless no_frontmatter
|
48
|
-
f.puts
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
85
|
+
f.puts YAML.dump({
|
86
|
+
"layout" => "post",
|
87
|
+
"title" => post.title,
|
88
|
+
"date" => post.published_at.to_s,
|
89
|
+
"permalink" => post.permalink
|
90
|
+
})
|
91
|
+
f.puts "---"
|
54
92
|
end
|
55
93
|
end
|
56
94
|
end
|
@@ -13,7 +13,7 @@ module JekyllImport
|
|
13
13
|
node AS n \
|
14
14
|
LEFT OUTER JOIN term_node AS tn ON tn.nid = n.nid \
|
15
15
|
LEFT OUTER JOIN term_data AS td ON tn.tid = td.tid \
|
16
|
-
WHERE (
|
16
|
+
WHERE (%types%) \
|
17
17
|
AND n.vid = nr.vid \
|
18
18
|
GROUP BY n.nid"
|
19
19
|
|
@@ -31,6 +31,7 @@ module JekyllImport
|
|
31
31
|
c.option 'password', '--password PW', "Database user's password (default: '')"
|
32
32
|
c.option 'host', '--host HOST', 'Database host name (default: "localhost")'
|
33
33
|
c.option 'prefix', '--prefix PREFIX', 'Table prefix name'
|
34
|
+
c.option 'types', '--types TYPE1[,TYPE2[,TYPE3...]]', Array, 'The Drupal content types to be imported.'
|
34
35
|
end
|
35
36
|
|
36
37
|
def self.require_deps
|
@@ -48,6 +49,7 @@ module JekyllImport
|
|
48
49
|
pass = options.fetch('password', "")
|
49
50
|
host = options.fetch('host', "localhost")
|
50
51
|
prefix = options.fetch('prefix', "")
|
52
|
+
types = options.fetch('types', ['blog', 'story', 'article'])
|
51
53
|
|
52
54
|
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
|
53
55
|
|
@@ -58,6 +60,9 @@ module JekyllImport
|
|
58
60
|
QUERY[" term_data "] = " " + prefix + "term_data "
|
59
61
|
end
|
60
62
|
|
63
|
+
types = types.join("' OR n.type = '")
|
64
|
+
QUERY[" WHERE (%types%) "] = " WHERE (n.type = '#{types}') "
|
65
|
+
|
61
66
|
FileUtils.mkdir_p "_posts"
|
62
67
|
FileUtils.mkdir_p "_drafts"
|
63
68
|
FileUtils.mkdir_p "_layouts"
|
@@ -7,12 +7,16 @@ module JekyllImport
|
|
7
7
|
fdb.body_value, \
|
8
8
|
fdb.body_summary, \
|
9
9
|
n.created, \
|
10
|
-
n.status \
|
10
|
+
n.status, \
|
11
|
+
n.nid, \
|
12
|
+
u.name \
|
11
13
|
FROM node AS n, \
|
12
|
-
field_data_body AS fdb \
|
13
|
-
|
14
|
+
field_data_body AS fdb, \
|
15
|
+
users AS u \
|
16
|
+
WHERE (%types%) \
|
14
17
|
AND n.nid = fdb.entity_id \
|
15
|
-
AND n.vid = fdb.revision_id
|
18
|
+
AND n.vid = fdb.revision_id
|
19
|
+
AND n.uid = u.uid"
|
16
20
|
|
17
21
|
def self.validate(options)
|
18
22
|
%w[dbname user].each do |option|
|
@@ -28,6 +32,7 @@ module JekyllImport
|
|
28
32
|
c.option 'password', '--password PW', 'Database user\'s password (default: "")'
|
29
33
|
c.option 'host', '--host HOST', 'Database host name (default: "localhost")'
|
30
34
|
c.option 'prefix', '--prefix PREFIX', 'Table prefix name'
|
35
|
+
c.option 'types', '--types TYPE1[,TYPE2[,TYPE3...]]', Array, 'The Drupal content types to be imported.'
|
31
36
|
end
|
32
37
|
|
33
38
|
def self.require_deps
|
@@ -45,14 +50,19 @@ module JekyllImport
|
|
45
50
|
pass = options.fetch('password', "")
|
46
51
|
host = options.fetch('host', "localhost")
|
47
52
|
prefix = options.fetch('prefix', "")
|
53
|
+
types = options.fetch('types', ['blog', 'story', 'article'])
|
48
54
|
|
49
55
|
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
|
50
56
|
|
51
57
|
unless prefix.empty?
|
52
58
|
QUERY[" node "] = " " + prefix + "node "
|
53
59
|
QUERY[" field_data_body "] = " " + prefix + "field_data_body "
|
60
|
+
QUERY[" users "] = " " + prefix + "users "
|
54
61
|
end
|
55
62
|
|
63
|
+
types = types.join("' OR n.type = '")
|
64
|
+
QUERY[" WHERE (%types%) "] = " WHERE (n.type = '#{types}') "
|
65
|
+
|
56
66
|
FileUtils.mkdir_p "_posts"
|
57
67
|
FileUtils.mkdir_p "_drafts"
|
58
68
|
FileUtils.mkdir_p "_layouts"
|
@@ -63,6 +73,8 @@ module JekyllImport
|
|
63
73
|
content = post[:body_value]
|
64
74
|
summary = post[:body_summary]
|
65
75
|
created = post[:created]
|
76
|
+
author = post[:name]
|
77
|
+
nid = post[:nid]
|
66
78
|
time = Time.at(created)
|
67
79
|
is_published = post[:status] == 1
|
68
80
|
dir = is_published ? "_posts" : "_drafts"
|
@@ -74,6 +86,8 @@ module JekyllImport
|
|
74
86
|
data = {
|
75
87
|
'layout' => 'post',
|
76
88
|
'title' => title.strip.force_encoding("UTF-8"),
|
89
|
+
'author' => author,
|
90
|
+
'nid' => nid,
|
77
91
|
'created' => created,
|
78
92
|
'excerpt' => summary
|
79
93
|
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
|
@@ -2,6 +2,8 @@ module JekyllImport
|
|
2
2
|
module Importers
|
3
3
|
class MT < Importer
|
4
4
|
|
5
|
+
SUPPORTED_ENGINES = %{mysql postgres sqlite}
|
6
|
+
|
5
7
|
STATUS_DRAFT = 1
|
6
8
|
STATUS_PUBLISHED = 2
|
7
9
|
MORE_CONTENT_SEPARATOR = '<!--more-->'
|
@@ -65,27 +67,10 @@ module JekyllImport
|
|
65
67
|
def self.process(options)
|
66
68
|
options = default_options.merge(options)
|
67
69
|
|
68
|
-
engine = options.fetch('engine', 'mysql')
|
69
|
-
dbname = options.fetch('dbname')
|
70
|
-
user = options.fetch('user')
|
71
|
-
pass = options.fetch('password', "")
|
72
|
-
host = options.fetch('host', "localhost")
|
73
70
|
comments = options.fetch('comments')
|
71
|
+
posts_name_by_id = {} if comments
|
74
72
|
|
75
|
-
|
76
|
-
|
77
|
-
db_opts = { user => user, :password => pass, :host => host }
|
78
|
-
|
79
|
-
# Use the default port by default, but set the port if one is provided.
|
80
|
-
if options['port']
|
81
|
-
db_opts[:port] = options['port']
|
82
|
-
end
|
83
|
-
|
84
|
-
if engine != 'mysql' && engine != 'postgres'
|
85
|
-
abort("unsupported --engine value supplied '#{engine}'. Only 'mysql' and 'postgres' are supported")
|
86
|
-
end
|
87
|
-
|
88
|
-
db = Sequel.public_send(engine, dbname, db_opts)
|
73
|
+
db = database_from_opts(options)
|
89
74
|
|
90
75
|
post_categories = db[:mt_placement].join(:mt_category, :category_id => :placement_category_id)
|
91
76
|
|
@@ -102,7 +87,7 @@ module JekyllImport
|
|
102
87
|
|
103
88
|
data = post_metadata(post, options)
|
104
89
|
data['categories'] = categories if !categories.empty? && options['categories']
|
105
|
-
yaml_front_matter = data.delete_if { |
|
90
|
+
yaml_front_matter = data.delete_if { |_,v| v.nil? || v == '' }.to_yaml
|
106
91
|
|
107
92
|
# save post path for comment processing
|
108
93
|
posts_name_by_id[data['post_id']] = file_name if comments
|
@@ -122,13 +107,13 @@ module JekyllImport
|
|
122
107
|
|
123
108
|
comments = db[:mt_comment]
|
124
109
|
comments.each do |comment|
|
125
|
-
if posts_name_by_id.
|
110
|
+
if posts_name_by_id.key?(comment[:comment_entry_id]) # if the entry exists
|
126
111
|
dir_name, base_name = comment_file_dir_and_base_name(posts_name_by_id, comment, options)
|
127
112
|
FileUtils.mkdir_p "_comments/#{dir_name}"
|
128
113
|
|
129
114
|
data = comment_metadata(comment, options)
|
130
115
|
content = comment_content(comment, options)
|
131
|
-
yaml_front_matter = data.delete_if { |
|
116
|
+
yaml_front_matter = data.delete_if { |_,v| v.nil? || v == '' }.to_yaml
|
132
117
|
|
133
118
|
File.open("_comments/#{dir_name}/#{base_name}", "w") do |f|
|
134
119
|
f.puts yaml_front_matter
|
@@ -243,6 +228,30 @@ module JekyllImport
|
|
243
228
|
entry_type
|
244
229
|
end
|
245
230
|
end
|
231
|
+
|
232
|
+
def self.database_from_opts(options)
|
233
|
+
engine = options.fetch('engine', 'mysql')
|
234
|
+
dbname = options.fetch('dbname')
|
235
|
+
|
236
|
+
case engine
|
237
|
+
when "sqlite"
|
238
|
+
Sequel.sqlite(dbname)
|
239
|
+
when "mysql", "postgres"
|
240
|
+
db_connect_opts = {
|
241
|
+
:host => options.fetch('host', 'localhost'),
|
242
|
+
:user => options.fetch('user'),
|
243
|
+
:password => options.fetch('password', '')
|
244
|
+
}
|
245
|
+
db_connect_opts = options['port'] if options['port']
|
246
|
+
Sequel.public_send(
|
247
|
+
engine,
|
248
|
+
dbname,
|
249
|
+
db_connect_opts
|
250
|
+
)
|
251
|
+
else
|
252
|
+
abort("Unsupported engine: '#{engine}'. Must be one of #{SUPPORTED_ENGINES.join(', ')}")
|
253
|
+
end
|
254
|
+
end
|
246
255
|
end
|
247
256
|
end
|
248
257
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Preston-Werner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -364,7 +364,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
364
364
|
version: '0'
|
365
365
|
requirements: []
|
366
366
|
rubyforge_project:
|
367
|
-
rubygems_version: 2.
|
367
|
+
rubygems_version: 2.5.1
|
368
368
|
signing_key:
|
369
369
|
specification_version: 2
|
370
370
|
summary: Import command for Jekyll (static site generator).
|