jekyll-import 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-import.rb +10 -8
  3. data/lib/jekyll-import/importer.rb +1 -1
  4. data/lib/jekyll-import/importers.rb +1 -1
  5. data/lib/jekyll-import/importers/behance.rb +20 -20
  6. data/lib/jekyll-import/importers/blogger.rb +108 -118
  7. data/lib/jekyll-import/importers/csv.rb +7 -7
  8. data/lib/jekyll-import/importers/drupal6.rb +5 -6
  9. data/lib/jekyll-import/importers/drupal7.rb +7 -13
  10. data/lib/jekyll-import/importers/drupal_common.rb +57 -59
  11. data/lib/jekyll-import/importers/easyblog.rb +30 -30
  12. data/lib/jekyll-import/importers/enki.rb +28 -29
  13. data/lib/jekyll-import/importers/ghost.rb +46 -33
  14. data/lib/jekyll-import/importers/google_reader.rb +9 -9
  15. data/lib/jekyll-import/importers/joomla.rb +32 -32
  16. data/lib/jekyll-import/importers/joomla3.rb +41 -39
  17. data/lib/jekyll-import/importers/jrnl.rb +16 -17
  18. data/lib/jekyll-import/importers/marley.rb +25 -26
  19. data/lib/jekyll-import/importers/mephisto.rb +26 -26
  20. data/lib/jekyll-import/importers/mt.rb +76 -75
  21. data/lib/jekyll-import/importers/posterous.rb +30 -29
  22. data/lib/jekyll-import/importers/rss.rb +13 -10
  23. data/lib/jekyll-import/importers/s9y.rb +16 -17
  24. data/lib/jekyll-import/importers/s9y_database.rb +98 -89
  25. data/lib/jekyll-import/importers/textpattern.rb +18 -17
  26. data/lib/jekyll-import/importers/tmp.rb +0 -0
  27. data/lib/jekyll-import/importers/tumblr.rb +146 -143
  28. data/lib/jekyll-import/importers/typo.rb +31 -31
  29. data/lib/jekyll-import/importers/wordpress.rb +100 -100
  30. data/lib/jekyll-import/importers/wordpressdotcom.rb +70 -60
  31. data/lib/jekyll-import/util.rb +24 -24
  32. data/lib/jekyll-import/version.rb +1 -1
  33. data/lib/jekyll/commands/import.rb +32 -35
  34. metadata +14 -13
@@ -4,22 +4,22 @@ module JekyllImport
4
4
  module Importers
5
5
  class CSV < Importer
6
6
  def self.require_deps
7
- JekyllImport.require_with_fallback(%w[
7
+ JekyllImport.require_with_fallback(%w(
8
8
  csv
9
9
  fileutils
10
10
  yaml
11
- ])
11
+ ))
12
12
  end
13
13
 
14
14
  def self.specify_options(c)
15
- c.option 'file', '--file NAME', 'The CSV file to import (default: "posts.csv")'
16
- c.option 'no-front-matter', '--no-front-matter', 'Do not add the default front matter to the post body'
15
+ c.option "file", "--file NAME", 'The CSV file to import (default: "posts.csv")'
16
+ c.option "no-front-matter", "--no-front-matter", "Do not add the default front matter to the post body"
17
17
  end
18
18
 
19
19
  # Reads a csv with title, permalink, body, published_at, and filter.
20
20
  # It creates a post file for each row in the csv
21
21
  def self.process(options)
22
- file = options.fetch('file', "posts.csv")
22
+ file = options.fetch("file", "posts.csv")
23
23
 
24
24
  FileUtils.mkdir_p "_posts"
25
25
  posts = 0
@@ -80,13 +80,13 @@ module JekyllImport
80
80
  end
81
81
 
82
82
  def self.write_frontmatter(f, post, options)
83
- no_frontmatter = options.fetch('no-front-matter', false)
83
+ no_frontmatter = options.fetch("no-front-matter", false)
84
84
  unless no_frontmatter
85
85
  f.puts YAML.dump({
86
86
  "layout" => "post",
87
87
  "title" => post.title,
88
88
  "date" => post.published_at.to_s,
89
- "permalink" => post.permalink
89
+ "permalink" => post.permalink,
90
90
  })
91
91
  f.puts "---"
92
92
  end
@@ -1,4 +1,4 @@
1
- require 'jekyll-import/importers/drupal_common'
1
+ require "jekyll-import/importers/drupal_common"
2
2
 
3
3
  module JekyllImport
4
4
  module Importers
@@ -38,16 +38,15 @@ EOS
38
38
  def self.post_data(sql_post_data)
39
39
  content = sql_post_data[:body].to_s
40
40
  summary = sql_post_data[:teaser].to_s
41
- tags = (sql_post_data[:tags] || '').downcase.strip
41
+ tags = (sql_post_data[:tags] || "").downcase.strip
42
42
 
43
43
  data = {
44
- 'excerpt' => summary,
45
- 'categories' => tags.split('|')
44
+ "excerpt" => summary,
45
+ "categories" => tags.split("|"),
46
46
  }
47
47
 
48
- return data, content
48
+ return data, content
49
49
  end
50
-
51
50
  end
52
51
  end
53
52
  end
@@ -1,4 +1,4 @@
1
- require 'jekyll-import/importers/drupal_common'
1
+ require "jekyll-import/importers/drupal_common"
2
2
 
3
3
  module JekyllImport
4
4
  module Importers
@@ -18,15 +18,10 @@ module JekyllImport
18
18
  n.created,
19
19
  n.status,
20
20
  n.type,
21
- GROUP_CONCAT( td.name SEPARATOR '|' ) AS 'tags'
22
- FROM #{prefix}field_data_body AS fdb,
23
- #{prefix}node AS n
24
- LEFT OUTER JOIN #{prefix}taxonomy_index AS ti ON ti.nid = n.nid
25
- LEFT OUTER JOIN #{prefix}taxonomy_term_data AS td ON ti.tid = td.tid
21
+ (SELECT GROUP_CONCAT(td.name SEPARATOR '|') FROM taxonomy_term_data td, taxonomy_index ti WHERE ti.tid = td.tid AND ti.nid = n.nid) AS 'tags'
22
+ FROM #{prefix}node AS n
23
+ LEFT JOIN #{prefix}field_data_body AS fdb ON fdb.entity_id = n.nid AND fdb.entity_type = 'node'
26
24
  WHERE (#{types})
27
- AND n.nid = fdb.entity_id
28
- AND n.vid = fdb.revision_id
29
- GROUP BY n.nid"
30
25
  EOS
31
26
 
32
27
  return query
@@ -39,16 +34,15 @@ EOS
39
34
  def self.post_data(sql_post_data)
40
35
  content = sql_post_data[:body_value].to_s
41
36
  summary = sql_post_data[:body_summary].to_s
42
- tags = (sql_post_data[:tags] || '').downcase.strip
37
+ tags = (sql_post_data[:tags] || "").downcase.strip
43
38
 
44
39
  data = {
45
- 'excerpt' => summary,
46
- 'categories' => tags.split('|')
40
+ "excerpt" => summary,
41
+ "categories" => tags.split("|"),
47
42
  }
48
43
 
49
44
  return data, content
50
45
  end
51
-
52
46
  end
53
47
  end
54
48
  end
@@ -1,4 +1,4 @@
1
- require 'date'
1
+ require "date"
2
2
 
3
3
  module JekyllImport
4
4
  module Importers
@@ -15,56 +15,57 @@ module JekyllImport
15
15
  "password" => "",
16
16
  "host" => "localhost",
17
17
  "prefix" => "",
18
- "types" => %w(blog story article)
19
- }
18
+ "types" => %w(blog story article),
19
+ }.freeze
20
20
 
21
21
  def specify_options(c)
22
- c.option 'dbname', '--dbname DB', 'Database name'
23
- c.option 'user', '--user USER', 'Database user name'
24
- c.option 'password', '--password PW', "Database user's password (default: #{DEFAULTS["password"].inspect})"
25
- c.option 'host', '--host HOST', "Database host name (default: #{DEFAULTS["host"].inspect})"
26
- c.option 'prefix', '--prefix PREFIX', "Table prefix name (default: #{DEFAULTS["prefix"].inspect})"
27
- c.option 'types', '--types TYPE1[,TYPE2[,TYPE3...]]', Array,
22
+ c.option "dbname", "--dbname DB", "Database name"
23
+ c.option "user", "--user USER", "Database user name"
24
+ c.option "password", "--password PW", "Database user's password (default: #{DEFAULTS["password"].inspect})"
25
+ c.option "host", "--host HOST", "Database host name (default: #{DEFAULTS["host"].inspect})"
26
+ c.option "prefix", "--prefix PREFIX", "Table prefix name (default: #{DEFAULTS["prefix"].inspect})"
27
+ c.option "types", "--types TYPE1[,TYPE2[,TYPE3...]]", Array,
28
28
  "The Drupal content types to be imported (default: #{DEFAULTS["types"].join(",")})"
29
29
  end
30
30
 
31
31
  def require_deps
32
- JekyllImport.require_with_fallback(%w[
32
+ JekyllImport.require_with_fallback(%w(
33
33
  rubygems
34
34
  sequel
35
+ mysql2
35
36
  fileutils
36
37
  safe_yaml
37
- ])
38
+ ))
38
39
  end
39
40
 
40
41
  def process(options)
41
- dbname = options.fetch('dbname')
42
- user = options.fetch('user')
43
- pass = options.fetch('password', DEFAULTS["password"])
44
- host = options.fetch('host', DEFAULTS["host"])
45
- prefix = options.fetch('prefix', DEFAULTS["prefix"])
46
- types = options.fetch('types', DEFAULTS["types"])
42
+ dbname = options.fetch("dbname")
43
+ user = options.fetch("user")
44
+ pass = options.fetch("password", DEFAULTS["password"])
45
+ host = options.fetch("host", DEFAULTS["host"])
46
+ prefix = options.fetch("prefix", DEFAULTS["prefix"])
47
+ types = options.fetch("types", DEFAULTS["types"])
47
48
 
48
- db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
49
+ db = Sequel.mysql2(dbname, :user => user, :password => pass, :host => host, :encoding => "utf8")
49
50
 
50
51
  query = self.build_query(prefix, types)
51
52
 
52
53
  conf = Jekyll.configuration({})
53
- src_dir = conf['source']
54
+ src_dir = conf["source"]
54
55
 
55
56
  dirs = {
56
- :_posts => File.join(src_dir, '_posts').to_s,
57
- :_drafts => File.join(src_dir, '_drafts').to_s,
58
- :_layouts => Jekyll.sanitized_path(src_dir, conf['layouts_dir'].to_s)
57
+ :_posts => File.join(src_dir, "_posts").to_s,
58
+ :_drafts => File.join(src_dir, "_drafts").to_s,
59
+ :_layouts => Jekyll.sanitized_path(src_dir, conf["layouts_dir"].to_s),
59
60
  }
60
61
 
61
- dirs.each do |key, dir|
62
+ dirs.each do |_key, dir|
62
63
  FileUtils.mkdir_p dir
63
64
  end
64
65
 
65
66
  # Create the refresh layout
66
67
  # Change the refresh url if you customized your permalink config
67
- File.open(File.join(dirs[:_layouts], 'refresh.html'), 'w') do |f|
68
+ File.open(File.join(dirs[:_layouts], "refresh.html"), "w") do |f|
68
69
  f.puts <<-HTML
69
70
  <!DOCTYPE html>
70
71
  <html>
@@ -80,78 +81,75 @@ HTML
80
81
  # Get required fields
81
82
  data, content = self.post_data(post)
82
83
 
83
- data['layout'] = post[:type]
84
- title = data['title'] = post[:title].strip.force_encoding('UTF-8')
85
- time = data['created'] = post[:created]
84
+ data["layout"] = post[:type]
85
+ title = data["title"] = post[:title].strip.force_encoding("UTF-8")
86
+ time = data["created"] = post[:created]
86
87
 
87
88
  # Get the relevant fields as a hash and delete empty fields
88
- data = data.delete_if { |k,v| v.nil? || v == ''}.each_pair {
89
- |k,v| ((v.is_a? String) ? v.force_encoding('UTF-8') : v)
90
- }
89
+ data = data.delete_if { |_k, v| v.nil? || v == "" }.each_pair do |_k, v|
90
+ (v.is_a? String ? v.force_encoding("UTF-8") : v)
91
+ end
91
92
 
92
93
  # Construct a Jekyll compatible file name
93
94
  is_published = post[:status] == 1
94
95
  node_id = post[:nid]
95
96
  dir = is_published ? dirs[:_posts] : dirs[:_drafts]
96
- slug = title.strip.downcase.gsub(/(&|&amp;)/, ' and ').gsub(/[\s\.\/\\]/, '-').gsub(/[^\w-]/, '').gsub(/[-_]{2,}/, '-').gsub(/^[-_]/, '').gsub(/[-_]$/, '')
97
- filename = Time.at(time).to_datetime.strftime('%Y-%m-%d-') + slug + '.md'
97
+ slug = title.strip.downcase.gsub(%r!(&|&amp;)!, " and ").gsub(%r![\s\.\/\\]!, "-").gsub(%r![^\w-]!, "").gsub(%r![-_]{2,}!, "-").gsub(%r!^[-_]!, "").gsub(%r![-_]$!, "")
98
+ filename = Time.at(time).to_datetime.strftime("%Y-%m-%d-") + slug + ".md"
98
99
 
99
100
  # Write out the data and content to file
100
- File.open("#{dir}/#{filename}", 'w') do |f|
101
+ File.open("#{dir}/#{filename}", "w") do |f|
101
102
  f.puts data.to_yaml
102
- f.puts '---'
103
+ f.puts "---"
103
104
  f.puts content
104
105
  end
105
106
 
106
-
107
107
  # Make a file to redirect from the old Drupal URL
108
- if is_published
109
- alias_query = self.aliases_query(prefix)
110
- type = post[:type]
111
-
112
- aliases = db[alias_query, "#{type}/#{node_id}"].all
113
-
114
- aliases.push(:alias => "#{type}/#{node_id}")
115
-
116
- aliases.each do |url_alias|
117
- FileUtils.mkdir_p url_alias[:alias]
118
- File.open("#{url_alias[:alias]}/index.md", "w") do |f|
119
- f.puts '---'
120
- f.puts 'layout: refresh'
121
- f.puts "refresh_to_post_id: /#{Time.at(time).to_datetime.strftime('%Y/%m/%d/') + slug}"
122
- f.puts '---'
123
- end
108
+ next unless is_published
109
+ alias_query = self.aliases_query(prefix)
110
+ type = post[:type]
111
+
112
+ aliases = db[alias_query, "#{type}/#{node_id}"].all
113
+
114
+ aliases.push(:alias => "#{type}/#{node_id}")
115
+
116
+ aliases.each do |url_alias|
117
+ FileUtils.mkdir_p url_alias[:alias]
118
+ File.open("#{url_alias[:alias]}/index.md", "w") do |f|
119
+ f.puts "---"
120
+ f.puts "layout: refresh"
121
+ f.puts "refresh_to_post_id: /#{Time.at(time).to_datetime.strftime("%Y/%m/%d/") + slug}"
122
+ f.puts "---"
124
123
  end
125
124
  end
126
125
  end
127
126
  end
128
127
  end
129
128
 
130
- def build_query(prefix, types)
131
- raise 'The importer you are trying to use does not implement the get_query() method.'
129
+ def build_query(_prefix, _types)
130
+ raise "The importer you are trying to use does not implement the get_query() method."
132
131
  end
133
132
 
134
- def aliases_query(prefix)
133
+ def aliases_query(_prefix)
135
134
  # Make sure you implement the query returning "alias" as the column name
136
135
  # for the URL aliases. See the Drupal 6 importer for an example. The
137
136
  # alias field is called 'dst' but we alias it to 'alias', to follow
138
137
  # Drupal 7's column names.
139
- raise 'The importer you are trying to use does not implement the get_aliases_query() method.'
138
+ raise "The importer you are trying to use does not implement the get_aliases_query() method."
140
139
  end
141
140
 
142
- def post_data(sql_post_data)
143
- raise 'The importer you are trying to use does not implement the get_query() method.'
141
+ def post_data(_sql_post_data)
142
+ raise "The importer you are trying to use does not implement the get_query() method."
144
143
  end
145
144
 
146
145
  def validate(options)
147
- %w[dbname user].each do |option|
146
+ %w(dbname user).each do |option|
148
147
  if options[option].nil?
149
148
  abort "Missing mandatory option --#{option}."
150
149
  end
151
150
  end
152
151
  end
153
152
 
154
-
155
153
  end
156
154
  end
157
155
  end
@@ -2,7 +2,7 @@ module JekyllImport
2
2
  module Importers
3
3
  class Easyblog < Importer
4
4
  def self.validate(options)
5
- %w[dbname user].each do |option|
5
+ %w(dbname user).each do |option|
6
6
  if options[option].nil?
7
7
  abort "Missing mandatory option --#{option}."
8
8
  end
@@ -10,32 +10,33 @@ module JekyllImport
10
10
  end
11
11
 
12
12
  def self.specify_options(c)
13
- c.option 'dbname', '--dbname', 'Database name'
14
- c.option 'user', '--user', 'Database user name'
15
- c.option 'password', '--password', "Database user's password (default: '')"
16
- c.option 'host', '--host', 'Database host name'
17
- c.option 'section', '--section', 'Table prefix name'
18
- c.option 'prefix', '--prefix', 'Table prefix name'
13
+ c.option "dbname", "--dbname", "Database name"
14
+ c.option "user", "--user", "Database user name"
15
+ c.option "password", "--password", "Database user's password (default: '')"
16
+ c.option "host", "--host", "Database host name"
17
+ c.option "section", "--section", "Table prefix name"
18
+ c.option "prefix", "--prefix", "Table prefix name"
19
19
  end
20
20
 
21
21
  def self.require_deps
22
- JekyllImport.require_with_fallback(%w[
23
- rubygems
24
- sequel
25
- fileutils
26
- safe_yaml
27
- ])
22
+ JekyllImport.require_with_fallback(%w(
23
+ rubygems
24
+ sequel
25
+ mysql2
26
+ fileutils
27
+ safe_yaml
28
+ ))
28
29
  end
29
30
 
30
31
  def self.process(options)
31
- dbname = options.fetch('dbname')
32
- user = options.fetch('user')
33
- pass = options.fetch('password', '')
34
- host = options.fetch('host', "localhost")
35
- section = options.fetch('section', '1')
36
- table_prefix = options.fetch('prefix', "jos_")
32
+ dbname = options.fetch("dbname")
33
+ user = options.fetch("user")
34
+ pass = options.fetch("password", "")
35
+ host = options.fetch("host", "localhost")
36
+ section = options.fetch("section", "1")
37
+ table_prefix = options.fetch("prefix", "jos_")
37
38
 
38
- db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
39
+ db = Sequel.mysql2(dbname, :user => user, :password => pass, :host => host, :encoding => "utf8")
39
40
 
40
41
  FileUtils.mkdir_p("_posts")
41
42
 
@@ -68,20 +69,19 @@ module JekyllImport
68
69
  content = post[:content]
69
70
  category = post[:category]
70
71
  tags = post[:tags]
71
- name = "%02d-%02d-%02d-%s.markdown" % [date.year, date.month, date.day,
72
- slug]
72
+ name = format("%02d-%02d-%02d-%s.markdown", date.year, date.month, date.day, slug)
73
73
 
74
74
  # Get the relevant fields as a hash, delete empty fields and convert
75
75
  # to YAML for the header.
76
76
  data = {
77
- 'layout' => 'post',
78
- 'title' => title.to_s,
79
- 'joomla_id' => post[:id],
80
- 'joomla_url' => post[:alias],
81
- 'category' => post[:category],
82
- 'tags' => post[:tags],
83
- 'date' => date
84
- }.delete_if { |k,v| v.nil? || v == '' }.to_yaml
77
+ "layout" => "post",
78
+ "title" => title.to_s,
79
+ "joomla_id" => post[:id],
80
+ "joomla_url" => post[:alias],
81
+ "category" => post[:category],
82
+ "tags" => post[:tags],
83
+ "date" => date,
84
+ }.delete_if { |_k, v| v.nil? || v == "" }.to_yaml
85
85
 
86
86
  # Write out the data and content to file
87
87
  File.open("_posts/#{name}", "w") do |f|
@@ -1,7 +1,7 @@
1
1
  module JekyllImport
2
- module Importers
2
+ module Importers
3
3
  class Enki < Importer
4
- SQL = <<-EOS
4
+ SQL = <<-EOS.freeze
5
5
  SELECT p.id,
6
6
  p.title,
7
7
  p.slug,
@@ -12,7 +12,7 @@ module JekyllImport
12
12
  EOS
13
13
 
14
14
  def self.validate(options)
15
- %w[dbname user].each do |option|
15
+ %w(dbname user).each do |option|
16
16
  if options[option].nil?
17
17
  abort "Missing mandatory option --#{option}."
18
18
  end
@@ -20,51 +20,50 @@ EOS
20
20
  end
21
21
 
22
22
  def self.specify_options(c)
23
- c.option 'dbname', '--dbname', 'Database name'
24
- c.option 'user', '--user', 'Database name'
25
- c.option 'password', '--password', 'Database name (default: "")'
26
- c.option 'host', '--host', 'Database name'
23
+ c.option "dbname", "--dbname", "Database name"
24
+ c.option "user", "--user", "Database name"
25
+ c.option "password", "--password", 'Database name (default: "")'
26
+ c.option "host", "--host", "Database name"
27
27
  end
28
28
 
29
29
  def self.require_deps
30
- JekyllImport.require_with_fallback(%w[
30
+ JekyllImport.require_with_fallback(%w(
31
31
  rubygems
32
32
  sequel
33
33
  fileutils
34
34
  pg
35
35
  yaml
36
- ])
36
+ ))
37
37
  end
38
38
 
39
39
  # Just working with postgres, but can be easily adapted
40
40
  # to work with both mysql and postgres.
41
41
  def self.process(options)
42
- dbname = options.fetch('dbname')
43
- user = options.fetch('user')
44
- pass = options.fetch('password', "")
45
- host = options.fetch('host', "localhost")
42
+ dbname = options.fetch("dbname")
43
+ user = options.fetch("user")
44
+ pass = options.fetch("password", "")
45
+ host = options.fetch("host", "localhost")
46
46
 
47
- FileUtils.mkdir_p('_posts')
47
+ FileUtils.mkdir_p("_posts")
48
48
  db = Sequel.postgres(:database => dbname,
49
- :user => user,
49
+ :user => user,
50
50
  :password => pass,
51
- :host => host,
52
- :encoding => 'utf8')
51
+ :host => host,
52
+ :encoding => "utf8")
53
53
 
54
54
  db[SQL].each do |post|
55
- name = [ sprintf("%.04d", post[:date].year),
56
- sprintf("%.02d", post[:date].month),
57
- sprintf("%.02d", post[:date].day),
58
- post[:slug].strip ].join('-')
59
- name += '.textile'
55
+ name = [ format("%.04d", post[:date].year),
56
+ format("%.02d", post[:date].month),
57
+ format("%.02d", post[:date].day),
58
+ post[:slug].strip, ].join("-")
59
+ name += ".textile"
60
60
 
61
- File.open("_posts/#{name}", 'w') do |f|
62
- f.puts({ 'layout' => 'post',
63
- 'title' => post[:title].to_s,
64
- 'enki_id' => post[:id],
65
- 'categories' => post[:tags]
66
- }.delete_if { |k, v| v.nil? || v == '' }.to_yaml)
67
- f.puts '---'
61
+ File.open("_posts/#{name}", "w") do |f|
62
+ f.puts({ "layout" => "post",
63
+ "title" => post[:title].to_s,
64
+ "enki_id" => post[:id],
65
+ "categories" => post[:tags], }.delete_if { |_k, v| v.nil? || v == "" }.to_yaml)
66
+ f.puts "---"
68
67
  f.puts post[:body].delete("\r")
69
68
  end
70
69
  end