jekyll-import 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-import.rb +2 -0
- data/lib/jekyll-import/importer.rb +5 -3
- data/lib/jekyll-import/importers.rb +3 -0
- data/lib/jekyll-import/importers/behance.rb +7 -6
- data/lib/jekyll-import/importers/blogger.rb +23 -38
- data/lib/jekyll-import/importers/csv.rb +6 -5
- data/lib/jekyll-import/importers/drupal6.rb +7 -5
- data/lib/jekyll-import/importers/drupal7.rb +15 -13
- data/lib/jekyll-import/importers/drupal_common.rb +55 -31
- data/lib/jekyll-import/importers/easyblog.rb +8 -8
- data/lib/jekyll-import/importers/enki.rb +14 -12
- data/lib/jekyll-import/importers/ghost.rb +4 -1
- data/lib/jekyll-import/importers/google_reader.rb +4 -4
- data/lib/jekyll-import/importers/joomla.rb +9 -9
- data/lib/jekyll-import/importers/joomla3.rb +15 -15
- data/lib/jekyll-import/importers/jrnl.rb +11 -9
- data/lib/jekyll-import/importers/marley.rb +12 -10
- data/lib/jekyll-import/importers/mephisto.rb +15 -15
- data/lib/jekyll-import/importers/mt.rb +16 -13
- data/lib/jekyll-import/importers/posterous.rb +12 -9
- data/lib/jekyll-import/importers/roller.rb +277 -0
- data/lib/jekyll-import/importers/rss.rb +18 -6
- data/lib/jekyll-import/importers/s9y.rb +3 -1
- data/lib/jekyll-import/importers/s9y_database.rb +38 -53
- data/lib/jekyll-import/importers/textpattern.rb +6 -4
- data/lib/jekyll-import/importers/tumblr.rb +101 -107
- data/lib/jekyll-import/importers/typo.rb +29 -27
- data/lib/jekyll-import/importers/wordpress.rb +47 -59
- data/lib/jekyll-import/importers/wordpressdotcom.rb +27 -32
- data/lib/jekyll-import/util.rb +2 -1
- data/lib/jekyll-import/version.rb +3 -1
- data/lib/jekyll/commands/import.rb +4 -7
- metadata +40 -40
- data/lib/jekyll-import/importers/tmp.rb +0 -0
@@ -1,21 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class Easyblog < Importer
|
4
6
|
def self.validate(options)
|
5
7
|
%w(dbname user).each do |option|
|
6
|
-
if options[option].nil?
|
7
|
-
abort "Missing mandatory option --#{option}."
|
8
|
-
end
|
8
|
+
abort "Missing mandatory option --#{option}." if options[option].nil?
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.specify_options(c)
|
13
|
-
c.option "dbname",
|
14
|
-
c.option "user",
|
13
|
+
c.option "dbname", "--dbname", "Database name"
|
14
|
+
c.option "user", "--user", "Database user name"
|
15
15
|
c.option "password", "--password", "Database user's password (default: '')"
|
16
|
-
c.option "host",
|
17
|
-
c.option "section",
|
18
|
-
c.option "prefix",
|
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
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class Enki < Importer
|
4
|
-
SQL =
|
6
|
+
SQL = <<~SQL
|
5
7
|
SELECT p.id,
|
6
8
|
p.title,
|
7
9
|
p.slug,
|
@@ -9,21 +11,19 @@ module JekyllImport
|
|
9
11
|
p.published_at as date,
|
10
12
|
p.cached_tag_list as tags
|
11
13
|
FROM posts p
|
12
|
-
|
14
|
+
SQL
|
13
15
|
|
14
16
|
def self.validate(options)
|
15
17
|
%w(dbname user).each do |option|
|
16
|
-
if options[option].nil?
|
17
|
-
abort "Missing mandatory option --#{option}."
|
18
|
-
end
|
18
|
+
abort "Missing mandatory option --#{option}." if options[option].nil?
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.specify_options(c)
|
23
|
-
c.option "dbname",
|
24
|
-
c.option "user",
|
23
|
+
c.option "dbname", "--dbname", "Database name"
|
24
|
+
c.option "user", "--user", "Database name"
|
25
25
|
c.option "password", "--password", 'Database name (default: "")'
|
26
|
-
c.option "host",
|
26
|
+
c.option "host", "--host", "Database name"
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.require_deps
|
@@ -52,10 +52,12 @@ EOS
|
|
52
52
|
:encoding => "utf8")
|
53
53
|
|
54
54
|
db[SQL].each do |post|
|
55
|
-
name = [
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
name = [
|
56
|
+
format("%.04d", post[:date].year),
|
57
|
+
format("%.02d", post[:date].month),
|
58
|
+
format("%.02d", post[:date].day),
|
59
|
+
post[:slug].strip,
|
60
|
+
].join("-")
|
59
61
|
name += ".textile"
|
60
62
|
|
61
63
|
File.open("_posts/#{name}", "w") do |f|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class Ghost < Importer
|
@@ -26,8 +28,9 @@ module JekyllImport
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
private
|
30
31
|
class << self
|
32
|
+
private
|
33
|
+
|
31
34
|
def fetch_posts(dbfile)
|
32
35
|
db = Sequel.sqlite(dbfile)
|
33
36
|
query = "SELECT `title`, `slug`, `markdown`, `created_at`, `published_at`, `status`, `page` FROM posts"
|
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class GoogleReader < Importer
|
4
6
|
def self.validate(options)
|
5
|
-
if options["source"].nil?
|
6
|
-
abort "Missing mandatory option --source."
|
7
|
-
end
|
7
|
+
abort "Missing mandatory option --source." if options["source"].nil?
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.specify_options(c)
|
@@ -31,7 +31,7 @@ module JekyllImport
|
|
31
31
|
def self.process(options)
|
32
32
|
source = options.fetch("source")
|
33
33
|
|
34
|
-
|
34
|
+
URI.parse(source).open do |content|
|
35
35
|
feed = RSS::Parser.parse(content)
|
36
36
|
|
37
37
|
raise "There doesn't appear to be any RSS items at the source (#{source}) provided." unless feed
|
@@ -1,22 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class Joomla < Importer
|
4
6
|
def self.validate(options)
|
5
7
|
%w(dbname user).each do |option|
|
6
|
-
if options[option].nil?
|
7
|
-
abort "Missing mandatory option --#{option}."
|
8
|
-
end
|
8
|
+
abort "Missing mandatory option --#{option}." if options[option].nil?
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.specify_options(c)
|
13
|
-
c.option "dbname",
|
14
|
-
c.option "user",
|
13
|
+
c.option "dbname", "--dbname", "Database name"
|
14
|
+
c.option "user", "--user", "Database user name"
|
15
15
|
c.option "password", "--password", "Database user's password (default: '')"
|
16
|
-
c.option "host",
|
17
|
-
c.option "port",
|
18
|
-
c.option "section",
|
19
|
-
c.option "prefix",
|
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"
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.require_deps
|
@@ -1,22 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class Joomla3 < Importer
|
4
6
|
def self.validate(options)
|
5
7
|
%w(dbname user prefix).each do |option|
|
6
|
-
if options[option].nil?
|
7
|
-
abort "Missing mandatory option --#{option}."
|
8
|
-
end
|
8
|
+
abort "Missing mandatory option --#{option}." if options[option].nil?
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.specify_options(c)
|
13
|
-
c.option "dbname",
|
14
|
-
c.option "user",
|
13
|
+
c.option "dbname", "--dbname", "Database name"
|
14
|
+
c.option "user", "--user", "Database user name"
|
15
15
|
c.option "password", "--password", "Database user's password (default: '')"
|
16
|
-
c.option "host",
|
17
|
-
c.option "port",
|
16
|
+
c.option "host", "--host", "Database host name"
|
17
|
+
c.option "port", "--port", "Database port"
|
18
18
|
c.option "category", "--category", "ID of the category"
|
19
|
-
c.option "prefix",
|
19
|
+
c.option "prefix", "--prefix", "Table prefix name"
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.require_deps
|
@@ -30,12 +30,12 @@ module JekyllImport
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.process(options)
|
33
|
-
dbname
|
34
|
-
user
|
35
|
-
pass
|
36
|
-
host
|
37
|
-
port
|
38
|
-
cid
|
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
39
|
table_prefix = options.fetch("prefix", "jos_")
|
40
40
|
|
41
41
|
db = Sequel.mysql2(dbname, :user => user, :password => pass, :host => host, :port => port, :encoding => "utf8")
|
@@ -50,7 +50,7 @@ module JekyllImport
|
|
50
50
|
query << "JOIN `#{table_prefix}users` AS `u` ON `cn`.`created_by` = `u`.`id` "
|
51
51
|
query << "WHERE (`cn`.`state` = '1' OR `cn`.`state` = '2') " # Only published and archived content items to be imported
|
52
52
|
|
53
|
-
query << if cid
|
53
|
+
query << if cid.positive?
|
54
54
|
" AND `cn`.`catid` = '#{cid}' "
|
55
55
|
else
|
56
56
|
" AND `cn`.`catid` != '2' " # Filter out uncategorized content
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class Jrnl < Importer
|
@@ -10,10 +12,10 @@ module JekyllImport
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def self.specify_options(c)
|
13
|
-
c.option "file",
|
15
|
+
c.option "file", "--file FILENAME", 'Journal file (default: "~/journal.txt")'
|
14
16
|
c.option "time_format", "--time_format FORMAT", 'Time format of your journal (default: "%Y-%m-%d %H:%M")'
|
15
|
-
c.option "extension",
|
16
|
-
c.option "layout",
|
17
|
+
c.option "extension", "--extension EXT", 'Output extension (default: "md")'
|
18
|
+
c.option "layout", "--layout NAME", 'Output post layout (default: "post")'
|
17
19
|
end
|
18
20
|
|
19
21
|
# Reads a jrnl file and creates a new post for each entry
|
@@ -57,27 +59,27 @@ module JekyllImport
|
|
57
59
|
|
58
60
|
# strip body from jrnl entry
|
59
61
|
def self.get_post_content(content)
|
60
|
-
|
62
|
+
content[1]
|
61
63
|
end
|
62
64
|
|
63
65
|
# strip timestamp from the dateline
|
64
66
|
def self.get_date(content, offset)
|
65
|
-
|
67
|
+
content[0, offset]
|
66
68
|
end
|
67
69
|
|
68
70
|
# strip title from the dateline
|
69
71
|
def self.get_title(content, offset)
|
70
|
-
|
72
|
+
content[offset + 1, content.length]
|
71
73
|
end
|
72
74
|
|
73
75
|
# generate slug
|
74
76
|
def self.create_slug(title)
|
75
|
-
|
77
|
+
title.downcase.strip.tr(" ", "-").gsub(%r![^\w-]!, "")
|
76
78
|
end
|
77
79
|
|
78
80
|
# generate filename
|
79
81
|
def self.create_filename(date, slug, extension)
|
80
|
-
|
82
|
+
"#{Time.parse(date).strftime("%Y-%m-%d")}-#{slug}.#{extension}"
|
81
83
|
end
|
82
84
|
|
83
85
|
# Prepare YAML meta data
|
@@ -98,7 +100,7 @@ module JekyllImport
|
|
98
100
|
"title" => title,
|
99
101
|
"date" => Time.parse(date).strftime("%Y-%m-%d %H:%M %z"),
|
100
102
|
}.to_yaml
|
101
|
-
|
103
|
+
data
|
102
104
|
end
|
103
105
|
|
104
106
|
# Writes given data to file
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class Marley < Importer
|
@@ -42,13 +44,13 @@ module JekyllImport
|
|
42
44
|
|
43
45
|
# copied over from marley's app/lib/post.rb
|
44
46
|
file_content = File.read(f)
|
45
|
-
meta_content = file_content.slice!(
|
46
|
-
body = file_content.sub(
|
47
|
+
meta_content = file_content.slice!(regexp[:meta])
|
48
|
+
body = file_content.sub(regexp[:title], "").sub(regexp[:perex], "").strip
|
47
49
|
|
48
|
-
title = file_content.scan(
|
49
|
-
prerex = file_content.scan(
|
50
|
+
title = file_content.scan(regexp[:title]).first.to_s.strip
|
51
|
+
prerex = file_content.scan(regexp[:perex]).first.to_s.strip
|
50
52
|
published_on = DateTime.parse(post[:published_on]) rescue File.mtime(File.dirname(f))
|
51
|
-
meta = meta_content ? YAML.safe_load(meta_content.scan(
|
53
|
+
meta = meta_content ? YAML.safe_load(meta_content.scan(regexp[:meta]).to_s) : {}
|
52
54
|
meta["title"] = title
|
53
55
|
meta["layout"] = "post"
|
54
56
|
|
@@ -56,11 +58,11 @@ module JekyllImport
|
|
56
58
|
post_name = File.dirname(f).split(%r!/!).last.gsub(%r!\A\d+-!, "")
|
57
59
|
|
58
60
|
name = "#{formatted_date}-#{post_name}"
|
59
|
-
File.open("_posts/#{name}.markdown", "w") do |
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
File.open("_posts/#{name}.markdown", "w") do |post|
|
62
|
+
post.puts meta.to_yaml
|
63
|
+
post.puts "---\n"
|
64
|
+
post.puts "\n#{prerex}\n\n" if prerex
|
65
|
+
post.puts body
|
64
66
|
end
|
65
67
|
posts += 1
|
66
68
|
end
|
@@ -1,28 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class Mephisto < Importer
|
4
6
|
# Accepts a hash with database config variables, exports mephisto posts into a csv
|
5
7
|
# export PGPASSWORD if you must
|
6
8
|
def self.postgres(c)
|
7
|
-
sql =
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
sql = <<~SQL
|
10
|
+
BEGIN;
|
11
|
+
CREATE TEMP TABLE jekyll AS
|
12
|
+
SELECT title, permalink, body, published_at, filter FROM contents
|
13
|
+
WHERE user_id = 1 AND type = 'Article' ORDER BY published_at;
|
14
|
+
COPY jekyll TO STDOUT WITH CSV HEADER;
|
15
|
+
ROLLBACK;
|
14
16
|
SQL
|
15
17
|
command = %(psql -h #{c[:host] || "localhost"} -c "#{sql.strip}" #{c[:database]} #{c[:username]} -o #{c[:filename] || "posts.csv"})
|
16
|
-
|
18
|
+
Jekyll.logger.info "Executing:", command
|
17
19
|
`#{command}`
|
18
20
|
CSV.process
|
19
21
|
end
|
20
22
|
|
21
23
|
def self.validate(options)
|
22
24
|
%w(dbname user).each do |option|
|
23
|
-
if options[option].nil?
|
24
|
-
abort "Missing mandatory option --#{option}."
|
25
|
-
end
|
25
|
+
abort "Missing mandatory option --#{option}." if options[option].nil?
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -37,10 +37,10 @@ module JekyllImport
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def self.specify_options(c)
|
40
|
-
c.option "dbname",
|
41
|
-
c.option "user",
|
40
|
+
c.option "dbname", "--dbname DB", "Database name"
|
41
|
+
c.option "user", "--user USER", "Database user name"
|
42
42
|
c.option "password", "--password PW", "Database user's password (default: '')"
|
43
|
-
c.option "host",
|
43
|
+
c.option "host", "--host HOST", 'Database host name (default: "localhost")'
|
44
44
|
end
|
45
45
|
|
46
46
|
# This query will pull blog posts from all entries across all blogs. If
|
@@ -55,7 +55,7 @@ module JekyllImport
|
|
55
55
|
WHERE user_id = 1 AND \
|
56
56
|
type = 'Article' AND \
|
57
57
|
published_at IS NOT NULL \
|
58
|
-
ORDER BY published_at"
|
58
|
+
ORDER BY published_at"
|
59
59
|
|
60
60
|
def self.process(options)
|
61
61
|
dbname = options.fetch("dbname")
|
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class MT < Importer
|
4
|
-
SUPPORTED_ENGINES = %(mysql postgres sqlite).freeze
|
6
|
+
SUPPORTED_ENGINES = %w(mysql postgres sqlite).freeze
|
5
7
|
|
6
8
|
STATUS_DRAFT = 1
|
7
9
|
STATUS_PUBLISHED = 2
|
8
|
-
MORE_CONTENT_SEPARATOR = "<!--more-->"
|
10
|
+
MORE_CONTENT_SEPARATOR = "<!--more-->"
|
9
11
|
|
10
12
|
def self.default_options
|
11
13
|
{
|
@@ -30,17 +32,17 @@ module JekyllImport
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def self.specify_options(c)
|
33
|
-
c.option "engine",
|
34
|
-
c.option "dbname",
|
35
|
-
c.option "user",
|
36
|
-
c.option "password",
|
37
|
-
c.option "host",
|
38
|
-
c.option "port",
|
39
|
-
c.option "blog_id",
|
40
|
-
c.option "categories",
|
41
|
-
c.option "src_encoding",
|
35
|
+
c.option "engine", "--engine ENGINE", "Database engine, (default: 'mysql', postgres also supported)"
|
36
|
+
c.option "dbname", "--dbname DB", "Database name"
|
37
|
+
c.option "user", "--user USER", "Database user name"
|
38
|
+
c.option "password", "--password PW", "Database user's password, (default: '')"
|
39
|
+
c.option "host", "--host HOST", 'Database host name (default: "localhost")'
|
40
|
+
c.option "port", "--port PORT", "Custom database port connect to (optional)"
|
41
|
+
c.option "blog_id", "--blog_id ID", "Specify a single Movable Type blog ID to import (default: all blogs)"
|
42
|
+
c.option "categories", "--categories", "If true, save post's categories in its YAML front matter. (default: true)"
|
43
|
+
c.option "src_encoding", "--src_encoding ENCODING", "Encoding of strings from database. (default: UTF-8)"
|
42
44
|
c.option "dest_encoding", "--dest_encoding ENCODING", "Encoding of output strings. (default: UTF-8)"
|
43
|
-
c.option "comments",
|
45
|
+
c.option "comments", "--comments", "If true, output comments in _comments directory (default: false)"
|
44
46
|
end
|
45
47
|
|
46
48
|
# By default this migrator will include posts for all your MovableType blogs.
|
@@ -82,7 +84,7 @@ module JekyllImport
|
|
82
84
|
posts = posts.filter(:entry_blog_id => options["blog_id"]) if options["blog_id"]
|
83
85
|
posts.each do |post|
|
84
86
|
categories = post_categories.filter(
|
85
|
-
:
|
87
|
+
:placement_entry_id => post[:entry_id]
|
86
88
|
).map { |ea| encode(ea[:category_basename], options) }
|
87
89
|
|
88
90
|
file_name = post_file_name(post, options)
|
@@ -110,6 +112,7 @@ module JekyllImport
|
|
110
112
|
comments = db[:mt_comment]
|
111
113
|
comments.each do |comment|
|
112
114
|
next unless posts_name_by_id.key?(comment[:comment_entry_id]) # if the entry exists
|
115
|
+
|
113
116
|
dir_name, base_name = comment_file_dir_and_base_name(posts_name_by_id, comment, options)
|
114
117
|
FileUtils.mkdir_p "_comments/#{dir_name}"
|
115
118
|
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class Posterous < Importer
|
4
6
|
def self.specify_options(c)
|
5
|
-
c.option "email",
|
6
|
-
c.option "password",
|
7
|
+
c.option "email", "--email EMAIL", "Posterous email address"
|
8
|
+
c.option "password", "--password PW", "Posterous password"
|
7
9
|
c.option "api_token", "--token TOKEN", "Posterous API Token"
|
8
10
|
end
|
9
11
|
|
@@ -39,10 +41,11 @@ module JekyllImport
|
|
39
41
|
def self.fetch_images(directory, imgs)
|
40
42
|
def self.fetch_one(url, limit = 10)
|
41
43
|
raise ArgumentError, "HTTP redirect too deep" if limit.zero?
|
44
|
+
|
42
45
|
response = Net::HTTP.get_response(URI.parse(url))
|
43
46
|
case response
|
44
47
|
when Net::HTTPSuccess then response.body
|
45
|
-
when Net::HTTPRedirection then
|
48
|
+
when Net::HTTPRedirection then fetch_one(response["location"], limit - 1)
|
46
49
|
else
|
47
50
|
response.error!
|
48
51
|
end
|
@@ -54,14 +57,14 @@ module JekyllImport
|
|
54
57
|
fullurl = img["full"]["url"]
|
55
58
|
uri = URI.parse(fullurl)
|
56
59
|
imgname = uri.path.split("/")[-1]
|
57
|
-
imgdata =
|
58
|
-
open(directory + "/" + imgname, "wb") do |file|
|
60
|
+
imgdata = fetch_one(fullurl)
|
61
|
+
File.open(directory + "/" + imgname, "wb") do |file|
|
59
62
|
file.write imgdata
|
60
63
|
end
|
61
64
|
urls.push(directory + "/" + imgname)
|
62
65
|
end
|
63
66
|
|
64
|
-
|
67
|
+
urls
|
65
68
|
end
|
66
69
|
|
67
70
|
def self.process(options)
|
@@ -76,7 +79,7 @@ module JekyllImport
|
|
76
79
|
opts = defaults.merge(opts)
|
77
80
|
FileUtils.mkdir_p "_posts"
|
78
81
|
|
79
|
-
posts = JSON.parse(
|
82
|
+
posts = JSON.parse(fetch("/api/v2/users/me/sites/#{opts[:blog]}/posts?api_token=#{@api_token}").body)
|
80
83
|
page = 1
|
81
84
|
|
82
85
|
while posts.any?
|
@@ -94,7 +97,7 @@ module JekyllImport
|
|
94
97
|
post_imgs = post["media"]["images"]
|
95
98
|
if post_imgs.any?
|
96
99
|
img_dir = format("imgs/%s", basename)
|
97
|
-
img_urls =
|
100
|
+
img_urls = fetch_images(img_dir, post_imgs)
|
98
101
|
|
99
102
|
img_urls.map! do |url|
|
100
103
|
'<li><img src="' + opts[:base_path] + url + '"></li>'
|
@@ -123,7 +126,7 @@ module JekyllImport
|
|
123
126
|
end
|
124
127
|
|
125
128
|
page += 1
|
126
|
-
posts = JSON.parse(
|
129
|
+
posts = JSON.parse(fetch("/api/v2/users/me/sites/#{opts[:blog]}/posts?api_token=#{@api_token}&page=#{page}").body)
|
127
130
|
end
|
128
131
|
end
|
129
132
|
end
|