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
@@ -1,23 +1,23 @@
1
1
  module JekyllImport
2
2
  module Importers
3
3
  class Ghost < Importer
4
-
5
4
  def self.specify_options(c)
6
- c.option 'dbfile', '--dbfile', 'Database file (default: ghost.db)'
5
+ c.option "dbfile", "--dbfile", "Database file (default: ghost.db)"
7
6
  end
8
7
 
9
8
  def self.require_deps
10
- JekyllImport.require_with_fallback(%w[
9
+ JekyllImport.require_with_fallback(%w(
11
10
  rubygems
12
11
  sequel
12
+ sqlite3
13
13
  fileutils
14
14
  safe_yaml
15
- ])
15
+ ))
16
16
  end
17
17
 
18
18
  def self.process(options)
19
- posts = fetch_posts(options.fetch('dbfile', 'ghost.db'))
20
- if !posts.empty?
19
+ posts = fetch_posts(options.fetch("dbfile", "ghost.db"))
20
+ unless posts.empty?
21
21
  FileUtils.mkdir_p("_posts")
22
22
  FileUtils.mkdir_p("_drafts")
23
23
  posts.each do |post|
@@ -27,40 +27,53 @@ module JekyllImport
27
27
  end
28
28
 
29
29
  private
30
- def self.fetch_posts(dbfile)
31
- db = Sequel.sqlite(dbfile)
32
- query = "SELECT `title`, `slug`, `markdown`, `created_at`, `status` FROM posts"
33
- db[query]
34
- end
30
+ class << self
31
+ def fetch_posts(dbfile)
32
+ db = Sequel.sqlite(dbfile)
33
+ query = "SELECT `title`, `slug`, `markdown`, `created_at`, `published_at`, `status`, `page` FROM posts"
34
+ db[query]
35
+ end
36
+
37
+ def write_post_to_file(post)
38
+ # detect if the post is a draft
39
+ draft = post[:status].eql?("draft")
35
40
 
36
- def self.write_post_to_file(post)
37
- # detect if the post is a draft
38
- draft = post[:status].eql?('draft')
41
+ # detect if the post is considered a static page
42
+ page = post[:page]
39
43
 
40
- # Ghost saves the time in an weird format with 3 more numbers.
41
- # But the time is correct when we remove the last 3 numbers.
42
- date = Time.at(post[:created_at].to_i.to_s[0..-4].to_i)
44
+ # the publish date if the post has been published, creation date otherwise
45
+ date = Time.at(post[draft ? :created_at : :published_at].to_i)
43
46
 
44
- # the directory where the file will be saved to. either _drafts or _posts
45
- directory = draft ? "_drafts" : "_posts"
47
+ if page
48
+ # the filename under which the page is stored
49
+ filename = "#{post[:slug]}.markdown"
50
+ else
51
+ # the directory where the file will be saved to. either _drafts or _posts
52
+ directory = draft ? "_drafts" : "_posts"
46
53
 
47
- # the filename under which the post is stored
48
- filename = File.join(directory, "#{date.strftime('%Y-%m-%d')}-#{post[:slug]}.markdown")
54
+ # the filename under which the post is stored
55
+ filename = File.join(directory, "#{date.strftime("%Y-%m-%d")}-#{post[:slug]}.markdown")
56
+ end
49
57
 
50
- # the YAML FrontMatter
51
- frontmatter = { 'layout' => 'post', 'title' => post[:title] }
52
- frontmatter['date'] = date if !draft # only add the date to the frontmatter when the post is published
53
- frontmatter.delete_if { |k,v| v.nil? || v == '' } # removes empty fields
58
+ # the YAML FrontMatter
59
+ frontmatter = {
60
+ "layout" => page ? "page" : "post",
61
+ "title" => post[:title],
62
+ }
63
+ frontmatter["date"] = date if !page && !draft # only add the date to the frontmatter when the post is published
64
+ frontmatter["published"] = false if page && draft # set published to false for draft pages
65
+ frontmatter.delete_if { |_k, v| v.nil? || v == "" } # removes empty fields
54
66
 
55
- # write the posts to disk
56
- write_file(filename, frontmatter.to_yaml, post[:markdown])
57
- end
67
+ # write the posts to disk
68
+ write_file(filename, frontmatter.to_yaml, post[:markdown])
69
+ end
58
70
 
59
- def self.write_file(filename, frontmatter, content)
60
- File.open(filename, "w") do |f|
61
- f.puts frontmatter
62
- f.puts "---"
63
- f.puts content
71
+ def write_file(filename, frontmatter, content)
72
+ File.open(filename, "w") do |f|
73
+ f.puts frontmatter
74
+ f.puts "---"
75
+ f.puts content
76
+ end
64
77
  end
65
78
  end
66
79
  end
@@ -2,17 +2,17 @@ module JekyllImport
2
2
  module Importers
3
3
  class GoogleReader < Importer
4
4
  def self.validate(options)
5
- if options['source'].nil?
5
+ if options["source"].nil?
6
6
  abort "Missing mandatory option --source."
7
7
  end
8
8
  end
9
9
 
10
10
  def self.specify_options(c)
11
- c.option 'source', '--source', 'Source XML file of Google Reader export'
11
+ c.option "source", "--source", "Source XML file of Google Reader export"
12
12
  end
13
13
 
14
14
  def self.require_deps
15
- JekyllImport.require_with_fallback(%w[
15
+ JekyllImport.require_with_fallback(%w(
16
16
  rubygems
17
17
  rss
18
18
  fileutils
@@ -20,7 +20,7 @@ module JekyllImport
20
20
  open-uri
21
21
  rexml/document
22
22
  date
23
- ])
23
+ ))
24
24
  end
25
25
 
26
26
  # Process the import.
@@ -29,7 +29,7 @@ module JekyllImport
29
29
  #
30
30
  # Returns nothing.
31
31
  def self.process(options)
32
- source = options.fetch('source')
32
+ source = options.fetch("source")
33
33
 
34
34
  open(source) do |content|
35
35
  feed = RSS::Parser.parse(content)
@@ -40,13 +40,13 @@ module JekyllImport
40
40
  title = item.title.content.to_s
41
41
  formatted_date = Date.parse(item.published.to_s)
42
42
  post_name = title.split(%r{ |!|/|:|&|-|$|,}).map do |i|
43
- i.downcase if i != ''
44
- end.compact.join('-')
43
+ i.downcase if i != ""
44
+ end.compact.join("-")
45
45
  name = "#{formatted_date}-#{post_name}"
46
46
 
47
47
  header = {
48
- 'layout' => 'post',
49
- 'title' => title
48
+ "layout" => "post",
49
+ "title" => title,
50
50
  }
51
51
 
52
52
  FileUtils.mkdir_p("_posts")
@@ -2,7 +2,7 @@ module JekyllImport
2
2
  module Importers
3
3
  class Joomla < 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,34 +10,35 @@ 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 "port", "--port", "Database port"
18
+ c.option "section", "--section", "Table prefix name"
19
+ c.option "prefix", "--prefix", "Table prefix name"
19
20
  end
20
21
 
21
22
  def self.require_deps
22
- JekyllImport.require_with_fallback(%w[
23
+ JekyllImport.require_with_fallback(%w(
23
24
  rubygems
24
25
  sequel
25
26
  mysql2
26
27
  fileutils
27
28
  safe_yaml
28
- mysql
29
- ])
29
+ ))
30
30
  end
31
31
 
32
32
  def self.process(options)
33
- dbname = options.fetch('dbname')
34
- user = options.fetch('user')
35
- pass = options.fetch('password', '')
36
- host = options.fetch('host', "localhost")
37
- section = options.fetch('section', '1')
38
- table_prefix = options.fetch('prefix', "jos_")
33
+ dbname = options.fetch("dbname")
34
+ user = options.fetch("user")
35
+ pass = options.fetch("password", "")
36
+ host = options.fetch("host", "localhost")
37
+ port = options.fetch("port", 3306).to_i
38
+ section = options.fetch("section", "1")
39
+ table_prefix = options.fetch("prefix", "jos_")
39
40
 
40
- db = Sequel.mysql2(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
41
+ db = Sequel.mysql2(dbname, :user => user, :password => pass, :host => host, :port => port, :encoding => "utf8")
41
42
 
42
43
  FileUtils.mkdir_p("_posts")
43
44
 
@@ -55,24 +56,23 @@ module JekyllImport
55
56
 
56
57
  # Construct a slug from the title if alias field empty.
57
58
  # Remove illegal filename characters.
58
- if !post[:alias] or post[:alias].empty?
59
- slug = sluggify(post[:title])
60
- else
61
- slug = sluggify(post[:alias])
62
- end
59
+ slug = if !post[:alias] || post[:alias].empty?
60
+ sluggify(post[:title])
61
+ else
62
+ sluggify(post[:alias])
63
+ end
63
64
 
64
- name = "%02d-%02d-%02d-%03d-%s.markdown" % [date.year, date.month, date.day,
65
- id,slug]
65
+ name = format("%02d-%02d-%02d-%03d-%s.markdown", date.year, date.month, date.day, id, slug)
66
66
 
67
67
  # Get the relevant fields as a hash, delete empty fields and convert
68
68
  # to YAML for the header.
69
69
  data = {
70
- 'layout' => 'post',
71
- 'title' => title.to_s,
72
- 'joomla_id' => post[:id],
73
- 'joomla_url' => post[:alias],
74
- 'date' => date
75
- }.delete_if { |k,v| v.nil? || v == '' }.to_yaml
70
+ "layout" => "post",
71
+ "title" => title.to_s,
72
+ "joomla_id" => post[:id],
73
+ "joomla_url" => post[:alias],
74
+ "date" => date,
75
+ }.delete_if { |_k, v| v.nil? || v == "" }.to_yaml
76
76
 
77
77
  # Write out the data and content to file
78
78
  File.open("_posts/#{name}", "w") do |f|
@@ -84,8 +84,8 @@ module JekyllImport
84
84
  end
85
85
 
86
86
  # Borrowed from the Wordpress importer
87
- def self.sluggify( title )
88
- title = title.downcase.gsub(/[^0-9A-Za-z]+/, " ").strip.gsub(" ", "-")
87
+ def self.sluggify(title)
88
+ title.downcase.gsub(%r![^0-9A-Za-z]+!, " ").strip.tr(" ", "-")
89
89
  end
90
90
  end
91
91
  end
@@ -2,7 +2,7 @@ module JekyllImport
2
2
  module Importers
3
3
  class Joomla3 < Importer
4
4
  def self.validate(options)
5
- %w[dbname user prefix].each do |option|
5
+ %w(dbname user prefix).each do |option|
6
6
  if options[option].nil?
7
7
  abort "Missing mandatory option --#{option}."
8
8
  end
@@ -10,73 +10,75 @@ 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 'category', '--category', 'ID of the category'
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 "port", "--port", "Database port"
18
+ c.option "category", "--category", "ID of the category"
19
+ c.option "prefix", "--prefix", "Table prefix name"
19
20
  end
20
21
 
21
22
  def self.require_deps
22
- JekyllImport.require_with_fallback(%w[
23
+ JekyllImport.require_with_fallback(%w(
23
24
  rubygems
24
25
  sequel
26
+ mysql2
25
27
  fileutils
26
28
  safe_yaml
27
- ])
29
+ ))
28
30
  end
29
31
 
30
32
  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
- cid = options.fetch('category', 0)
36
- table_prefix = options.fetch('prefix', "jos_")
33
+ dbname = options.fetch("dbname")
34
+ user = options.fetch("user")
35
+ pass = options.fetch("password", "")
36
+ host = options.fetch("host", "localhost")
37
+ port = options.fetch("port", 3306).to_i
38
+ cid = options.fetch("category", 0)
39
+ table_prefix = options.fetch("prefix", "jos_")
37
40
 
38
- db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
41
+ db = Sequel.mysql2(dbname, :user => user, :password => pass, :host => host, :port => port, :encoding => "utf8")
39
42
 
40
43
  FileUtils.mkdir_p("_posts")
41
44
 
42
45
  # Reads a MySQL database via Sequel and creates a post file for each
43
46
  # post in #__content that is published.
44
47
  query = "SELECT `cn`.`title`, `cn`.`alias`, `cn`.`introtext`, CONCAT(`cn`.`introtext`,`cn`.`fulltext`) AS `content`, "
45
- query << "`cn`.`created`, `cn`.`id`, `ct`.`title` AS `category`, `u`.`name` AS `author` "
46
- query << "FROM `#{table_prefix}content` AS `cn` JOIN `#{table_prefix}categories` AS `ct` ON `cn`.`catid` = `ct`.`id` "
47
- query << "JOIN `#{table_prefix}users` AS `u` ON `cn`.`created_by` = `u`.`id` "
48
- query << "WHERE (`cn`.`state` = '1' OR `cn`.`state` = '2') " # Only published and archived content items to be imported
48
+ query << "`cn`.`created`, `cn`.`id`, `ct`.`title` AS `category`, `u`.`name` AS `author` "
49
+ query << "FROM `#{table_prefix}content` AS `cn` JOIN `#{table_prefix}categories` AS `ct` ON `cn`.`catid` = `ct`.`id` "
50
+ query << "JOIN `#{table_prefix}users` AS `u` ON `cn`.`created_by` = `u`.`id` "
51
+ query << "WHERE (`cn`.`state` = '1' OR `cn`.`state` = '2') " # Only published and archived content items to be imported
49
52
 
50
- if cid > 0
51
- query << " AND `cn`.`catid` = '#{cid}' "
52
- else
53
- query << " AND `cn`.`catid` != '2' " #Filter out uncategorized content
54
- end
53
+ query << if cid > 0
54
+ " AND `cn`.`catid` = '#{cid}' "
55
+ else
56
+ " AND `cn`.`catid` != '2' " # Filter out uncategorized content
57
+ end
55
58
 
56
59
  db[query].each do |post|
57
60
  # Get required fields and construct Jekyll compatible name.
58
61
  title = post[:title]
59
62
  slug = post[:alias]
60
63
  date = post[:created]
61
- author = post[:author]
62
- category = post[:category]
64
+ author = post[:author]
65
+ category = post[:category]
63
66
  content = post[:content]
64
- excerpt = post[:introtext]
65
- name = "%02d-%02d-%02d-%s.markdown" % [date.year, date.month, date.day,
66
- slug]
67
+ excerpt = post[:introtext]
68
+ name = format("%02d-%02d-%02d-%s.markdown", date.year, date.month, date.day, slug)
67
69
 
68
70
  # Get the relevant fields as a hash, delete empty fields and convert
69
71
  # to YAML for the header.
70
72
  data = {
71
- 'layout' => 'post',
72
- 'title' => title.to_s,
73
- 'joomla_id' => post[:id],
74
- 'joomla_url' => slug,
75
- 'date' => date,
76
- 'author' => author,
77
- 'excerpt' => excerpt.strip.to_s,
78
- 'category' => category
79
- }.delete_if { |k,v| v.nil? || v == '' }.to_yaml
73
+ "layout" => "post",
74
+ "title" => title.to_s,
75
+ "joomla_id" => post[:id],
76
+ "joomla_url" => slug,
77
+ "date" => date,
78
+ "author" => author,
79
+ "excerpt" => excerpt.strip.to_s,
80
+ "category" => category,
81
+ }.delete_if { |_k, v| v.nil? || v == "" }.to_yaml
80
82
 
81
83
  # Write out the data and content to file
82
84
  File.open("_posts/#{name}", "w") do |f|
@@ -1,20 +1,19 @@
1
1
  module JekyllImport
2
2
  module Importers
3
3
  class Jrnl < Importer
4
-
5
4
  def self.require_deps
6
- JekyllImport.require_with_fallback(%w[
5
+ JekyllImport.require_with_fallback(%w(
7
6
  time
8
7
  rubygems
9
8
  safe_yaml
10
- ])
9
+ ))
11
10
  end
12
11
 
13
12
  def self.specify_options(c)
14
- c.option 'file', '--file FILENAME', 'Journal file (default: "~/journal.txt")'
15
- c.option 'time_format', '--time_format FORMAT', 'Time format of your journal (default: "%Y-%m-%d %H:%M")'
16
- c.option 'extension', '--extension EXT', 'Output extension (default: "md")'
17
- c.option 'layout', '--layout NAME', 'Output post layout (default: "post")'
13
+ c.option "file", "--file FILENAME", 'Journal file (default: "~/journal.txt")'
14
+ c.option "time_format", "--time_format FORMAT", 'Time format of your journal (default: "%Y-%m-%d %H:%M")'
15
+ c.option "extension", "--extension EXT", 'Output extension (default: "md")'
16
+ c.option "layout", "--layout NAME", 'Output post layout (default: "post")'
18
17
  end
19
18
 
20
19
  # Reads a jrnl file and creates a new post for each entry
@@ -24,10 +23,10 @@ module JekyllImport
24
23
  # :extension the extension format of the output files
25
24
  # :layout explicitly set the layout of the output
26
25
  def self.process(options)
27
- file = options.fetch('file', "~/journal.txt")
28
- time_format = options.fetch('time_format', "%Y-%m-%d %H:%M")
29
- extension = options.fetch('extension', "md")
30
- layout = options.fetch('layout', "post")
26
+ file = options.fetch("file", "~/journal.txt")
27
+ time_format = options.fetch("time_format", "%Y-%m-%d %H:%M")
28
+ extension = options.fetch("extension", "md")
29
+ layout = options.fetch("layout", "post")
31
30
 
32
31
  date_length = Time.now.strftime(time_format).length
33
32
 
@@ -37,7 +36,7 @@ module JekyllImport
37
36
  abort "The jrnl file was not found. Please make sure '#{file}' exists. You can specify a different file using the --file switch." unless File.file?(file)
38
37
 
39
38
  input = File.read(file)
40
- entries = input.split("\n\n");
39
+ entries = input.split("\n\n")
41
40
 
42
41
  entries.each do |entry|
43
42
  # split dateline and body
@@ -73,7 +72,7 @@ module JekyllImport
73
72
 
74
73
  # generate slug
75
74
  def self.create_slug(title)
76
- return title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
75
+ return title.downcase.strip.tr(" ", "-").gsub(%r![^\w-]!, "")
77
76
  end
78
77
 
79
78
  # generate filename
@@ -95,11 +94,11 @@ module JekyllImport
95
94
  # Returns array converted to YAML
96
95
  def self.create_meta(layout, title, date)
97
96
  data = {
98
- 'layout' => layout,
99
- 'title' => title,
100
- 'date' => Time.parse(date).strftime("%Y-%m-%d %H:%M %z")
97
+ "layout" => layout,
98
+ "title" => title,
99
+ "date" => Time.parse(date).strftime("%Y-%m-%d %H:%M %z"),
101
100
  }.to_yaml
102
- return data;
101
+ return data
103
102
  end
104
103
 
105
104
  # Writes given data to file