jekyll-import 0.14.0 → 0.15.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 +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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dc36b6cb2508c37bc5af40022d3a56f75c5ccaf1ae60ab631db9986f4d0a799
|
4
|
+
data.tar.gz: c0ab3fd214f121e75e5388143344a2c5501d2e81e1205db004c8510c01e2ae1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0701c36d3cf270e612e1d8292447b870e3c6a3db0904d57b8f3c5a4fedb195fa6586aa840e666b325fc291f15fca95d1a17fe05e6556a95ef59c7128784e732
|
7
|
+
data.tar.gz: 5355d89fbe103c753cc9b48ac6d3f398e6a980a1a86a0e19e69ba0e8cc3967a188db6ba45eb515e3a711a2e55b23f768c3b3583534b6ec8760010828bc855c8b
|
data/lib/jekyll-import.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
class Importer
|
3
5
|
def self.inherited(base)
|
@@ -18,9 +20,9 @@ module JekyllImport
|
|
18
20
|
|
19
21
|
def self.run(options = {})
|
20
22
|
opts = stringify_keys(options)
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
require_deps
|
24
|
+
validate(opts) if respond_to?(:validate)
|
25
|
+
process(opts)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class Behance < Importer
|
@@ -12,15 +14,13 @@ module JekyllImport
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def self.specify_options(c)
|
15
|
-
c.option "user",
|
17
|
+
c.option "user", "--user NAME", "The username of the account"
|
16
18
|
c.option "api_token", "--api_token TOKEN", "The API access token for the account"
|
17
19
|
end
|
18
20
|
|
19
21
|
def self.validate(options)
|
20
22
|
%w(user api_token).each do |option|
|
21
|
-
if options[option].nil?
|
22
|
-
abort "Missing mandatory option --#{option}."
|
23
|
-
end
|
23
|
+
abort "Missing mandatory option --#{option}." if options[option].nil?
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -38,7 +38,7 @@ module JekyllImport
|
|
38
38
|
|
39
39
|
user_projects = client.user_projects(user)
|
40
40
|
|
41
|
-
|
41
|
+
Jekyll.logger.info "#{user_projects.length} project(s) found. Importing now..."
|
42
42
|
|
43
43
|
user_projects.each do |project|
|
44
44
|
details = client.project(project["id"])
|
@@ -66,11 +66,12 @@ module JekyllImport
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
Jekyll.logger.info "Finished importing."
|
70
70
|
end
|
71
71
|
|
72
72
|
class << self
|
73
73
|
private
|
74
|
+
|
74
75
|
def fetch_behance(token)
|
75
76
|
::Behance::Client.new(:access_token => token)
|
76
77
|
end
|
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JekyllImport
|
2
4
|
module Importers
|
3
5
|
class Blogger < Importer
|
4
6
|
def self.specify_options(c)
|
5
|
-
c.option "source",
|
6
|
-
c.option "no-blogger-info",
|
7
|
-
c.option "replace-internal-link",
|
8
|
-
c.option "comments",
|
7
|
+
c.option "source", "--source NAME", "The XML file (blog-MM-DD-YYYY.xml) path to import"
|
8
|
+
c.option "no-blogger-info", "--no-blogger-info", "not to leave blogger-URL info (id and old URL) in the front matter (default: false)"
|
9
|
+
c.option "replace-internal-link", "--replace-internal-link", "replace internal links using the post_url liquid tag. (default: false)"
|
10
|
+
c.option "comments", "--comments", "import comments to _comments collection"
|
9
11
|
end
|
10
12
|
|
11
13
|
def self.validate(options)
|
@@ -41,8 +43,8 @@ module JekyllImport
|
|
41
43
|
|
42
44
|
listener = BloggerAtomStreamListener.new
|
43
45
|
|
44
|
-
listener.leave_blogger_info = !options.fetch("no-blogger-info", false)
|
45
|
-
listener.comments = options.fetch("comments", false)
|
46
|
+
listener.leave_blogger_info = !options.fetch("no-blogger-info", false)
|
47
|
+
listener.comments = options.fetch("comments", false)
|
46
48
|
|
47
49
|
File.open(source, "r") do |f|
|
48
50
|
f.flock(File::LOCK_SH)
|
@@ -78,6 +80,7 @@ module JekyllImport
|
|
78
80
|
quote = Regexp.last_match(1)
|
79
81
|
post_file = Dir.glob("_posts/#{Regexp.last_match(2)}-#{Regexp.last_match(3)}-*-#{Regexp.last_match(4).to_s.tr("/", "-")}").first
|
80
82
|
raise "Could not found: _posts/#{Regexp.last_match(2)}-#{Regexp.last_match(3)}-*-#{Regexp.last_match(4).to_s.tr("/", "-")}" if post_file.nil?
|
83
|
+
|
81
84
|
" href=#{quote}{{ site.baseurl }}{% post_url #{File.basename(post_file, ".html")} %}#{quote}"
|
82
85
|
end
|
83
86
|
|
@@ -106,12 +109,13 @@ module JekyllImport
|
|
106
109
|
attr_reader :original_url_base
|
107
110
|
|
108
111
|
def tag_start(tag, attrs)
|
109
|
-
@tag_bread
|
112
|
+
@tag_bread ||= []
|
110
113
|
@tag_bread.push(tag)
|
111
114
|
|
112
115
|
case tag
|
113
116
|
when "entry"
|
114
117
|
raise "nest entry element" if @in_entry_elem
|
118
|
+
|
115
119
|
@in_entry_elem = { :meta => {}, :body => nil }
|
116
120
|
when "title"
|
117
121
|
if @in_entry_elem
|
@@ -129,9 +133,7 @@ module JekyllImport
|
|
129
133
|
end
|
130
134
|
end
|
131
135
|
when "content"
|
132
|
-
if @in_entry_elem
|
133
|
-
@in_entry_elem[:meta][:content_type] = attrs["type"]
|
134
|
-
end
|
136
|
+
@in_entry_elem[:meta][:content_type] = attrs["type"] if @in_entry_elem
|
135
137
|
when "link"
|
136
138
|
if @in_entry_elem
|
137
139
|
if attrs["rel"] == "alternate" && attrs["type"] == "text/html"
|
@@ -143,13 +145,9 @@ module JekyllImport
|
|
143
145
|
end
|
144
146
|
end
|
145
147
|
when "media:thumbnail"
|
146
|
-
if @in_entry_elem
|
147
|
-
@in_entry_elem[:meta][:thumbnail] = attrs["url"]
|
148
|
-
end
|
148
|
+
@in_entry_elem[:meta][:thumbnail] = attrs["url"] if @in_entry_elem
|
149
149
|
when "thr:in-reply-to"
|
150
|
-
if @in_entry_elem
|
151
|
-
@in_entry_elem[:meta][:post_id] = attrs["ref"]
|
152
|
-
end
|
150
|
+
@in_entry_elem[:meta][:post_id] = attrs["ref"] if @in_entry_elem
|
153
151
|
end
|
154
152
|
end
|
155
153
|
|
@@ -167,9 +165,7 @@ module JekyllImport
|
|
167
165
|
when "content"
|
168
166
|
@in_entry_elem[:body] = text
|
169
167
|
when "name"
|
170
|
-
if @tag_bread[-2..-1] == %w(author name)
|
171
|
-
@in_entry_elem[:meta][:author] = text
|
172
|
-
end
|
168
|
+
@in_entry_elem[:meta][:author] = text if @tag_bread[-2..-1] == %w(author name)
|
173
169
|
when "app:draft"
|
174
170
|
if @tag_bread[-2..-1] == %w(app:control app:draft)
|
175
171
|
@in_entry_elem[:meta][:draft] = true if text == "yes"
|
@@ -184,7 +180,7 @@ module JekyllImport
|
|
184
180
|
raise "nest entry element" unless @in_entry_elem
|
185
181
|
|
186
182
|
if @in_entry_elem[:meta][:kind] == "post"
|
187
|
-
post_data =
|
183
|
+
post_data = post_data_from_in_entry_elem_info
|
188
184
|
|
189
185
|
if post_data
|
190
186
|
target_dir = "_posts"
|
@@ -202,7 +198,7 @@ module JekyllImport
|
|
202
198
|
end
|
203
199
|
end
|
204
200
|
elsif @in_entry_elem[:meta][:kind] == "comment" && @comments
|
205
|
-
post_data =
|
201
|
+
post_data = post_data_from_in_entry_elem_info
|
206
202
|
|
207
203
|
if post_data
|
208
204
|
target_dir = "_comments"
|
@@ -226,7 +222,7 @@ module JekyllImport
|
|
226
222
|
@tag_bread.pop
|
227
223
|
end
|
228
224
|
|
229
|
-
def
|
225
|
+
def post_data_from_in_entry_elem_info
|
230
226
|
if @in_entry_elem.nil? || !@in_entry_elem.key?(:meta) || !@in_entry_elem[:meta].key?(:kind)
|
231
227
|
nil
|
232
228
|
elsif @in_entry_elem[:meta][:kind] == "post"
|
@@ -264,20 +260,14 @@ module JekyllImport
|
|
264
260
|
body = @in_entry_elem[:body]
|
265
261
|
|
266
262
|
# body escaping associated with liquid
|
267
|
-
if body =~ %r!{{!
|
268
|
-
|
269
|
-
end
|
270
|
-
if body =~ %r!{%!
|
271
|
-
body.gsub!(%r!{%!, '{{ "{%" }}')
|
272
|
-
end
|
263
|
+
body.gsub!(%r!{{!, '{{ "{{" }}') if body =~ %r!{{!
|
264
|
+
body.gsub!(%r!{%!, '{{ "{%" }}') if body =~ %r!{%!
|
273
265
|
|
274
266
|
{ :filename => filename, :header => header, :body => body }
|
275
267
|
elsif @in_entry_elem[:meta][:kind] == "comment"
|
276
268
|
timestamp = Time.parse(@in_entry_elem[:meta][:published]).strftime("%Y-%m-%d")
|
277
269
|
if @in_entry_elem[:meta][:original_url]
|
278
|
-
|
279
|
-
@comment_seq = 1
|
280
|
-
end
|
270
|
+
@comment_seq ||= 1
|
281
271
|
|
282
272
|
original_uri = URI.parse(@in_entry_elem[:meta][:original_url])
|
283
273
|
original_path = original_uri.path.to_s
|
@@ -303,17 +293,12 @@ module JekyllImport
|
|
303
293
|
body = @in_entry_elem[:body]
|
304
294
|
|
305
295
|
# body escaping associated with liquid
|
306
|
-
if body =~ %r!{{!
|
307
|
-
|
308
|
-
end
|
309
|
-
if body =~ %r!{%!
|
310
|
-
body.gsub!(%r!{%!, '{{ "{%" }}')
|
311
|
-
end
|
296
|
+
body.gsub!(%r!{{!, '{{ "{{" }}') if body =~ %r!{{!
|
297
|
+
body.gsub!(%r!{%!, '{{ "{%" }}') if body =~ %r!{%!
|
312
298
|
|
313
299
|
{ :filename => filename, :header => header, :body => body }
|
314
300
|
end
|
315
301
|
end
|
316
|
-
|
317
302
|
end
|
318
303
|
end
|
319
304
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module JekyllImport
|
4
4
|
module Importers
|
@@ -12,7 +12,7 @@ module JekyllImport
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.specify_options(c)
|
15
|
-
c.option "file",
|
15
|
+
c.option "file", "--file NAME", 'The CSV file to import (default: "posts.csv")'
|
16
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
|
|
@@ -27,6 +27,7 @@ module JekyllImport
|
|
27
27
|
|
28
28
|
::CSV.foreach(file) do |row|
|
29
29
|
next if row[0] == "title" # header
|
30
|
+
|
30
31
|
posts += 1
|
31
32
|
write_post(CSVPost.new(row), options)
|
32
33
|
end
|
@@ -82,12 +83,12 @@ module JekyllImport
|
|
82
83
|
def self.write_frontmatter(f, post, options)
|
83
84
|
no_frontmatter = options.fetch("no-front-matter", false)
|
84
85
|
unless no_frontmatter
|
85
|
-
f.puts YAML.dump(
|
86
|
+
f.puts YAML.dump(
|
86
87
|
"layout" => "post",
|
87
88
|
"title" => post.title,
|
88
89
|
"date" => post.published_at.to_s,
|
89
|
-
"permalink" => post.permalink
|
90
|
-
|
90
|
+
"permalink" => post.permalink
|
91
|
+
)
|
91
92
|
f.puts "---"
|
92
93
|
end
|
93
94
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "jekyll-import/importers/drupal_common"
|
2
4
|
|
3
5
|
module JekyllImport
|
@@ -6,11 +8,11 @@ module JekyllImport
|
|
6
8
|
include DrupalCommon
|
7
9
|
extend DrupalCommon::ClassMethods
|
8
10
|
|
9
|
-
def self.build_query(prefix, types,
|
11
|
+
def self.build_query(prefix, types, _engine)
|
10
12
|
types = types.join("' OR n.type = '")
|
11
13
|
types = "n.type = '#{types}'"
|
12
14
|
|
13
|
-
query = <<
|
15
|
+
query = <<SQL
|
14
16
|
SELECT n.nid,
|
15
17
|
n.title,
|
16
18
|
nr.body,
|
@@ -26,9 +28,9 @@ module JekyllImport
|
|
26
28
|
WHERE (#{types})
|
27
29
|
AND n.vid = nr.vid
|
28
30
|
GROUP BY n.nid
|
29
|
-
|
31
|
+
SQL
|
30
32
|
|
31
|
-
|
33
|
+
query
|
32
34
|
end
|
33
35
|
|
34
36
|
def self.aliases_query(prefix)
|
@@ -45,7 +47,7 @@ EOS
|
|
45
47
|
"categories" => tags.split("|"),
|
46
48
|
}
|
47
49
|
|
48
|
-
|
50
|
+
[data, content]
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "jekyll-import/importers/drupal_common"
|
2
4
|
|
3
5
|
module JekyllImport
|
@@ -10,21 +12,21 @@ module JekyllImport
|
|
10
12
|
types = types.join("' OR n.type = '")
|
11
13
|
types = "n.type = '#{types}'"
|
12
14
|
|
13
|
-
if engine == "postgresql"
|
14
|
-
|
15
|
+
tag_group = if engine == "postgresql"
|
16
|
+
<<POSTGRESQL
|
15
17
|
(SELECT STRING_AGG(td.name, '|')
|
16
|
-
FROM taxonomy_term_data td, taxonomy_index ti
|
18
|
+
FROM #{prefix}taxonomy_term_data td, #{prefix}taxonomy_index ti
|
17
19
|
WHERE ti.tid = td.tid AND ti.nid = n.nid) AS tags
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
POSTGRESQL
|
21
|
+
else
|
22
|
+
<<SQL
|
21
23
|
(SELECT GROUP_CONCAT(td.name SEPARATOR '|')
|
22
|
-
FROM taxonomy_term_data td, taxonomy_index ti
|
24
|
+
FROM #{prefix}taxonomy_term_data td, #{prefix}taxonomy_index ti
|
23
25
|
WHERE ti.tid = td.tid AND ti.nid = n.nid) AS 'tags'
|
24
|
-
|
25
|
-
|
26
|
+
SQL
|
27
|
+
end
|
26
28
|
|
27
|
-
query = <<
|
29
|
+
query = <<QUERY
|
28
30
|
SELECT n.nid,
|
29
31
|
n.title,
|
30
32
|
fdb.body_value,
|
@@ -37,9 +39,9 @@ EOS
|
|
37
39
|
LEFT JOIN #{prefix}field_data_body AS fdb
|
38
40
|
ON fdb.entity_id = n.nid AND fdb.entity_type = 'node'
|
39
41
|
WHERE (#{types})
|
40
|
-
|
42
|
+
QUERY
|
41
43
|
|
42
|
-
|
44
|
+
query
|
43
45
|
end
|
44
46
|
|
45
47
|
def self.aliases_query(prefix)
|
@@ -56,7 +58,7 @@ EOS
|
|
56
58
|
"categories" => tags.split("|"),
|
57
59
|
}
|
58
60
|
|
59
|
-
|
61
|
+
[data, content]
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "date"
|
2
4
|
|
3
5
|
module JekyllImport
|
@@ -16,18 +18,21 @@ module JekyllImport
|
|
16
18
|
"password" => "",
|
17
19
|
"host" => "localhost",
|
18
20
|
"prefix" => "",
|
21
|
+
"port" => "3306",
|
19
22
|
"types" => %w(blog story article),
|
20
23
|
}.freeze
|
21
24
|
|
22
25
|
def specify_options(c)
|
23
|
-
c.option "engine",
|
24
|
-
c.option "dbname",
|
25
|
-
c.option "user",
|
26
|
-
c.option "password", "--password PW",
|
27
|
-
c.option "host",
|
28
|
-
c.option "
|
29
|
-
c.option "
|
30
|
-
|
26
|
+
c.option "engine", "--engine [mysql|postgresql]", "Database engine (default: #{DEFAULTS["engine"].inspect})"
|
27
|
+
c.option "dbname", "--dbname DB", "Database name"
|
28
|
+
c.option "user", "--user USER", "Database user name"
|
29
|
+
c.option "password", "--password PW", "Database user's password (default: #{DEFAULTS["password"].inspect})"
|
30
|
+
c.option "host", "--host HOST", "Database host name (default: #{DEFAULTS["host"].inspect})"
|
31
|
+
c.option "port", "--port PORT", "Database port name (default: #{DEFAULTS["port"].inspect})"
|
32
|
+
c.option "prefix", "--prefix PREFIX", "Table prefix name (default: #{DEFAULTS["prefix"].inspect})"
|
33
|
+
|
34
|
+
c.option "types", "--types TYPE1[,TYPE2[,TYPE3...]]", Array,
|
35
|
+
"The Drupal content types to be imported (default: #{DEFAULTS["types"].join(",")})"
|
31
36
|
end
|
32
37
|
|
33
38
|
def require_deps
|
@@ -42,21 +47,22 @@ module JekyllImport
|
|
42
47
|
end
|
43
48
|
|
44
49
|
def process(options)
|
45
|
-
engine = options.fetch("engine")
|
50
|
+
engine = options.fetch("engine", DEFAULTS["engine"])
|
46
51
|
dbname = options.fetch("dbname")
|
47
52
|
user = options.fetch("user")
|
48
53
|
pass = options.fetch("password", DEFAULTS["password"])
|
49
54
|
host = options.fetch("host", DEFAULTS["host"])
|
55
|
+
port = options.fetch("port", DEFAULTS["port"])
|
50
56
|
prefix = options.fetch("prefix", DEFAULTS["prefix"])
|
51
57
|
types = options.fetch("types", DEFAULTS["types"])
|
52
58
|
|
53
59
|
if engine == "postgresql"
|
54
60
|
db = Sequel.postgres(dbname, :user => user, :password => pass, :host => host, :encoding => "utf8")
|
55
61
|
else
|
56
|
-
db = Sequel.mysql2(dbname, :user => user, :password => pass, :host => host, :encoding => "utf8")
|
62
|
+
db = Sequel.mysql2(dbname, :user => user, :password => pass, :host => host, :port => port, :encoding => "utf8")
|
57
63
|
end
|
58
64
|
|
59
|
-
query =
|
65
|
+
query = build_query(prefix, types, engine)
|
60
66
|
|
61
67
|
conf = Jekyll.configuration({})
|
62
68
|
src_dir = conf["source"]
|
@@ -74,20 +80,21 @@ module JekyllImport
|
|
74
80
|
# Create the refresh layout
|
75
81
|
# Change the refresh url if you customized your permalink config
|
76
82
|
File.open(File.join(dirs[:_layouts], "refresh.html"), "w") do |f|
|
77
|
-
f.puts
|
78
|
-
<!DOCTYPE html>
|
79
|
-
<html>
|
80
|
-
<head>
|
81
|
-
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
82
|
-
<meta http-equiv="refresh" content="0;url={{ page.refresh_to_post_id }}.html" />
|
83
|
-
|
84
|
-
</
|
85
|
-
|
83
|
+
f.puts <<~HTML
|
84
|
+
<!DOCTYPE html>
|
85
|
+
<html>
|
86
|
+
<head>
|
87
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
88
|
+
<meta http-equiv="refresh" content="0;url={{ page.refresh_to_post_id }}.html" />
|
89
|
+
<link rel="canonical" href="{{ page.refresh_to_post_id }}.html" />
|
90
|
+
</head>
|
91
|
+
</html>
|
92
|
+
HTML
|
86
93
|
end
|
87
94
|
|
88
95
|
db[query].each do |post|
|
89
96
|
# Get required fields
|
90
|
-
data, content =
|
97
|
+
data, content = post_data(post)
|
91
98
|
|
92
99
|
data["layout"] = post[:type]
|
93
100
|
title = data["title"] = post[:title].strip.force_encoding("UTF-8")
|
@@ -95,7 +102,7 @@ HTML
|
|
95
102
|
|
96
103
|
# Get the relevant fields as a hash and delete empty fields
|
97
104
|
data = data.delete_if { |_k, v| v.nil? || v == "" }.each_pair do |_k, v|
|
98
|
-
|
105
|
+
v.is_a?(String) ? v.force_encoding("UTF-8") : v
|
99
106
|
end
|
100
107
|
|
101
108
|
# Construct a Jekyll compatible file name
|
@@ -114,19 +121,39 @@ HTML
|
|
114
121
|
|
115
122
|
# Make a file to redirect from the old Drupal URL
|
116
123
|
next unless is_published
|
117
|
-
|
124
|
+
|
125
|
+
alias_query = aliases_query(prefix)
|
118
126
|
type = post[:type]
|
119
127
|
|
120
|
-
|
128
|
+
aliases_type = db[alias_query, "#{type}/#{node_id}"].all
|
129
|
+
aliases_node = db[alias_query, "node/#{node_id}"].all
|
130
|
+
aliases = aliases_type.concat aliases_node
|
121
131
|
|
122
132
|
aliases.push(:alias => "#{type}/#{node_id}")
|
133
|
+
aliases.push(:alias => "node/#{node_id}")
|
123
134
|
|
124
135
|
aliases.each do |url_alias|
|
125
|
-
|
126
|
-
|
136
|
+
redirect_prefix = ""
|
137
|
+
categories = data["categories"]
|
138
|
+
unless categories.nil? || categories.length.zero?
|
139
|
+
first_category = categories[0]
|
140
|
+
redirect_prefix = "#{first_category}/"
|
141
|
+
end
|
142
|
+
|
143
|
+
partition = url_alias[:alias].rpartition("/")
|
144
|
+
dir = ""
|
145
|
+
file = partition.last
|
146
|
+
|
147
|
+
if partition.first.length.positive?
|
148
|
+
dir = "#{partition.first}/"
|
149
|
+
FileUtils.mkdir_p partition.first
|
150
|
+
end
|
151
|
+
|
152
|
+
File.open("#{dir}#{file}.md", "w") do |f|
|
127
153
|
f.puts "---"
|
128
154
|
f.puts "layout: refresh"
|
129
|
-
f.puts "
|
155
|
+
f.puts "permalink: #{dir}#{file}/"
|
156
|
+
f.puts "refresh_to_post_id: /#{redirect_prefix}#{Time.at(time).to_datetime.strftime("%Y/%m/%d/") + slug}"
|
130
157
|
f.puts "---"
|
131
158
|
end
|
132
159
|
end
|
@@ -152,12 +179,9 @@ HTML
|
|
152
179
|
|
153
180
|
def validate(options)
|
154
181
|
%w(dbname user).each do |option|
|
155
|
-
|
156
|
-
abort "Missing mandatory option --#{option}."
|
157
|
-
end
|
182
|
+
abort "Missing mandatory option --#{option}." unless options.key?(option)
|
158
183
|
end
|
159
184
|
end
|
160
|
-
|
161
185
|
end
|
162
186
|
end
|
163
187
|
end
|