jekyll-import 0.18.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3f964d35053d8b6d57507e51d0f6512da6090196fbc64d5b27707841bd911dd
4
- data.tar.gz: 6473e0c7e9619af1e666c845337bff7f553ec104106bfec56f366c5623446431
3
+ metadata.gz: 334724ebd0dbdc9774dd2e4799dea04dc5adaacc911d05cfc26f2a5daf23bbfa
4
+ data.tar.gz: 79a4f8c6de087aebca9f726275ebb3c234361b7341a01ce10c544ff65a0b6bac
5
5
  SHA512:
6
- metadata.gz: f549ada882d1255c0bcb35a7945b19101de4b7b2c352ae13631b452da9f3dd59fd5dc36f45a51cf815c4c15c89f04575eba7d172d222e3bc21a18c42857e2796
7
- data.tar.gz: bc2dd8ed440e6df361aefcf6059a9762e9692d1726b95a4748498819626e595f7c36a7d7d09acf10fa79b22f79b344e7f89f6207f2bbdd4825db131164c16e39
6
+ metadata.gz: d716d81c1e596e1004a65eadaa6c4df3e130d134d0b3db0fef7e06151350a90525f59db50aefd6f771950b0698f174fe19311dca7134c3488be970b85e76737a
7
+ data.tar.gz: f5ee7ba0c29bfad8267482789e2f571ee2d6ccafd343d173c9e9408b1c6c9c25941f28476386c3076310ec630fc5ff84c7ef12aaac2bc934aa1b8ee8e11010f5
@@ -12,7 +12,7 @@ module JekyllImport
12
12
 
13
13
  def self.stringify_keys(hash)
14
14
  the_hash = hash.clone
15
- the_hash.keys.each do |key|
15
+ hash.each_key do |key|
16
16
  the_hash[(key.to_s rescue key) || key] = the_hash.delete(key)
17
17
  end
18
18
  the_hash
@@ -258,8 +258,8 @@ module JekyllImport
258
258
  body = @in_entry_elem[:body]
259
259
 
260
260
  # body escaping associated with liquid
261
- body.gsub!(%r!{{!, '{{ "{{" }}') if body =~ %r!{{!
262
- body.gsub!(%r!{%!, '{{ "{%" }}') if body =~ %r!{%!
261
+ body.gsub!(%r!{{!, '{{ "{{" }}') if %r!{{!.match?(body)
262
+ body.gsub!(%r!{%!, '{{ "{%" }}') if %r!{%!.match?(body)
263
263
 
264
264
  { :filename => filename, :header => header, :body => body }
265
265
  elsif @in_entry_elem[:meta][:kind] == "comment"
@@ -291,8 +291,8 @@ module JekyllImport
291
291
  body = @in_entry_elem[:body]
292
292
 
293
293
  # body escaping associated with liquid
294
- body.gsub!(%r!{{!, '{{ "{{" }}') if body =~ %r!{{!
295
- body.gsub!(%r!{%!, '{{ "{%" }}') if body =~ %r!{%!
294
+ body.gsub!(%r!{{!, '{{ "{{" }}') if %r!{{!.match?(body)
295
+ body.gsub!(%r!{%!, '{{ "{%" }}') if %r!{%!.match?(body)
296
296
 
297
297
  { :filename => filename, :header => header, :body => body }
298
298
  end
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Tested with dotClear 2.1.5
4
+ module JekyllImport
5
+ module Importers
6
+ class Dotclear < Importer
7
+ def self.specify_options(c)
8
+ c.option "datafile", "--datafile PATH", "dotClear export file"
9
+ c.option "mediafolder", "--mediafolder PATH", "dotClear media export folder (media.zip inflated)"
10
+ end
11
+
12
+ def self.require_deps
13
+ JekyllImport.require_with_fallback(%w(
14
+ rubygems
15
+ fileutils
16
+ safe_yaml
17
+ date
18
+ active_support
19
+ active_support/core_ext/string/inflections
20
+ csv
21
+ pp
22
+ ))
23
+ end
24
+
25
+ def self.validate(opts)
26
+ abort "Specify a data file !" if opts["datafile"].nil? || opts["datafile"].empty?
27
+ abort "Specify a media folder !" if opts["mediafolder"].nil? || opts["mediafolder"].empty?
28
+ end
29
+
30
+ def self.extract_headers_section(str)
31
+ str[1..-2].split(" ")[1].split(",")
32
+ end
33
+
34
+ def self.extract_data_section(str)
35
+ str.gsub(%r!^"!, "").gsub(%r!"$!, "").split('","')
36
+ end
37
+
38
+ def self.process(opts)
39
+ options = {
40
+ :datafile => opts.fetch("datafile", ""),
41
+ :mediafolder => opts.fetch("mediafolder", ""),
42
+ }
43
+
44
+ FileUtils.mkdir_p("_posts")
45
+ FileUtils.mkdir_p("_drafts")
46
+
47
+ type_data = ""
48
+ headers = {}
49
+ posts_and_drafts = {}
50
+ keywords = {}
51
+
52
+ File.readlines(options[:datafile]).each do |lineraw|
53
+ line = lineraw.strip.gsub(%r!\n$!, "")
54
+
55
+ next if line.empty?
56
+
57
+ if line.start_with?("[") # post | media \ meta | comment...
58
+ type_data = line.split(" ").first[1..-1]
59
+ headers[type_data] = extract_headers_section(line)
60
+ next
61
+ end
62
+
63
+ elts = extract_data_section(line)
64
+
65
+ if type_data == "post"
66
+ draft = (elts[headers[type_data].index("post_status")] != "1")
67
+
68
+ date_str = elts[headers[type_data].index("post_creadt")]
69
+ date_blank = (date_str.nil? || date_str.empty?)
70
+ date_str_formatted = date_blank ? Date.today : Date.parse(date_str).strftime("%Y-%m-%d")
71
+ title_param = elts[headers[type_data].index("post_title")].to_s.parameterize
72
+
73
+ content = elts[headers[type_data].index("post_content_xhtml")].to_s
74
+ content = content.gsub('\"', '"').gsub('\n', "\n").gsub("/public/", "/assets/images/")
75
+
76
+ filepath = File.join(Dir.pwd, (draft ? "_drafts" : "_posts"), "#{date_str_formatted}-#{title_param}.html")
77
+
78
+ entire_content_file = <<~POST_FILE
79
+ ---
80
+ layout: post
81
+ title: "#{elts[headers[type_data].index("post_title")]}"
82
+ date: #{elts[headers[type_data].index("post_creadt")]} +0100
83
+ tags: ABC
84
+ ---
85
+
86
+ #{content}
87
+ POST_FILE
88
+
89
+ posts_and_drafts[elts[headers[type_data].index("post_id")]] = { :path => filepath, :content => entire_content_file }
90
+ elsif type_data == "media"
91
+ elts[headers[type_data].index("media_title")]
92
+ mediafilepath = elts[headers[type_data].index("media_file")]
93
+
94
+ src_path = File.join(options[:mediafolder], mediafilepath)
95
+ dst_path = File.join(Dir.pwd, "assets", "images", mediafilepath.to_s)
96
+
97
+ FileUtils.mkdir_p(File.dirname(dst_path))
98
+ FileUtils.cp(src_path, dst_path)
99
+ elsif type_data == "meta"
100
+ keywords[elts[headers[type_data].index("post_id")]] ||= []
101
+ keywords[elts[headers[type_data].index("post_id")]] << elts[headers[type_data].index("meta_id")]
102
+ elsif type_data == "link"
103
+
104
+ elsif type_data == "setting"
105
+
106
+ elsif type_data == "comment"
107
+
108
+ end
109
+ end
110
+
111
+ # POST-process : Change media path in posts and drafts
112
+ posts_and_drafts.each do |post_id, hsh|
113
+ keywords_str = keywords[post_id].to_a.join(", ")
114
+ content_file = hsh[:content]
115
+ content_file = content_file.gsub("tags: ABC", "tags: [#{keywords_str}]")
116
+
117
+ File.open(hsh[:path], "wb") do |f|
118
+ f.write(content_file)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -48,7 +48,7 @@ module JekyllImport
48
48
  title = file_content.scan(regexp[:title]).first.to_s.strip
49
49
  prerex = file_content.scan(regexp[:perex]).first.to_s.strip
50
50
  published_on = DateTime.parse(post[:published_on]) rescue File.mtime(File.dirname(f))
51
- meta = meta_content ? YAML.safe_load(meta_content.scan(regexp[:meta]).to_s) : {}
51
+ meta = meta_content ? YAML.safe_load(meta_content.scan(regexp[:meta]).to_s) : {}
52
52
  meta["title"] = title
53
53
  meta["layout"] = "post"
54
54
 
@@ -31,7 +31,7 @@ module JekyllImport
31
31
  rubygems
32
32
  sequel
33
33
  mysql2
34
- fastercsv
34
+ csv
35
35
  fileutils
36
36
  ))
37
37
  end
@@ -69,7 +69,7 @@ module JekyllImport
69
69
  # comments:: If true, output comments in _comments directory, like the one
70
70
  # mentioned at https://github.com/mpalmer/jekyll-static-comments/
71
71
  def self.process(options)
72
- options = default_options.merge(options)
72
+ options = default_options.merge(options)
73
73
 
74
74
  comments = options.fetch("comments")
75
75
  posts_name_by_id = {} if comments
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllImport
4
+ module Importers
5
+ class Pluxml < Importer
6
+ def self.require_deps
7
+ JekyllImport.require_with_fallback(%w(
8
+ nokogiri
9
+ fileutils
10
+ safe_yaml
11
+ ))
12
+ end
13
+
14
+ def self.specify_options(c)
15
+ c.option "source", "--source NAME", "The PluXML data directory to import"
16
+ c.option "layout", "--layout NAME", "The layout to apply"
17
+ c.option "avoid_liquid", "--avoid_liquid true", "Will add render_with_liquid: false in frontmatter"
18
+ end
19
+
20
+ def self.validate(options)
21
+ abort "Missing mandatory option --source." if options["source"].nil?
22
+ # no layout option, layout by default is post
23
+ options["layout"] = "post" if options["layout"].nil?
24
+ # no avoid_liquid option, avoid_liquid by default is false
25
+ options["avoid_liquid"] = false if options["avoid_liquid"].nil?
26
+ end
27
+
28
+ def self.process(options)
29
+ source = options.fetch("source")
30
+ layout = options.fetch("layout")
31
+ avoid_liquid = options.fetch("avoid_liquid")
32
+
33
+ FileUtils.mkdir_p("_posts")
34
+ FileUtils.mkdir_p("_drafts")
35
+
36
+ # for each XML file in source location
37
+ Dir.glob("*.xml", :base => source).each do |df|
38
+ df = File.join(source, df)
39
+ filename = File.basename(df, ".*")
40
+
41
+ # prepare post file name in Jekyll format
42
+ a_filename = filename.split(".")
43
+ post_name = a_filename.pop
44
+ file_date = a_filename.pop
45
+ post_date = file_date[0..3] + "-" + file_date[4..5] + "-" + file_date[6..7]
46
+
47
+ # if draft, only take post name
48
+ if filename.split(".")[1].split(",")[0] == "draft"
49
+ directory = "_drafts"
50
+ name = post_name.to_s
51
+ # if post, post date precede post name
52
+ else
53
+ directory = "_posts"
54
+ name = "#{post_date}-#{post_name}"
55
+ end
56
+
57
+ xml = File.open(df) { |f| Nokogiri::XML(f) }
58
+ raise "There doesn't appear to be any XML items at the source (#{df}) provided." unless xml
59
+
60
+ doc = xml.xpath("document")
61
+ header = {
62
+ "layout" => layout,
63
+ "title" => doc.xpath("title").text,
64
+ "tags" => doc.xpath("tags").text.split(", "),
65
+ }
66
+ header["render_with_liquid"] = false if avoid_liquid
67
+
68
+ path = File.join(directory, "#{name}.html")
69
+ File.open(path, "w") do |f|
70
+ f.puts header.to_yaml
71
+ f.puts "---\n\n"
72
+ f.puts doc.xpath("chapo").text
73
+ f.puts doc.xpath("content").text
74
+ end
75
+
76
+ Jekyll.logger.info "Wrote file #{path} successfully!"
77
+ end
78
+ nil
79
+ end
80
+ end
81
+ end
82
+ end
@@ -80,7 +80,7 @@ module JekyllImport
80
80
  begin
81
81
  require "htmlentities"
82
82
  rescue LoadError
83
- STDERR.puts "Could not require 'htmlentities', so the :clean_entities option is now disabled."
83
+ warn "Could not require 'htmlentities', so the :clean_entities option is now disabled."
84
84
  options[:clean_entities] = false
85
85
  end
86
86
  end
@@ -41,9 +41,7 @@ module JekyllImport
41
41
 
42
42
  rss.items.each do |item|
43
43
  formatted_date = item.date.strftime("%Y-%m-%d")
44
- post_name = item.title.split(%r{ |!|/|:|&|-|$|,}).map do |i|
45
- i.downcase if i != ""
46
- end.compact.join("-")
44
+ post_name = Jekyll::Utils.slugify(item.title, :mode => "latin")
47
45
  name = "#{formatted_date}-#{post_name}"
48
46
 
49
47
  header = {
@@ -51,18 +49,21 @@ module JekyllImport
51
49
  "title" => item.title,
52
50
  }
53
51
 
54
- header["tag"] = options["tag"] unless options.to_s.empty?
52
+ header["tag"] = options["tag"] unless options["tag"].nil? || options["tag"].empty?
55
53
 
56
54
  frontmatter.each do |value|
57
55
  header[value] = item.send(value)
58
56
  end
59
57
 
60
- output = ""
58
+ output = +""
61
59
 
62
60
  body.each do |row|
63
- output += item.send(row)
61
+ output << item.send(row).to_s
64
62
  end
65
63
 
64
+ output.strip!
65
+ output = item.content_encoded if output.empty?
66
+
66
67
  FileUtils.mkdir_p("_posts")
67
68
 
68
69
  File.open("_posts/#{name}.html", "w") do |f|
@@ -207,7 +207,7 @@ module JekyllImport
207
207
  require gem_name
208
208
  true
209
209
  rescue LoadError
210
- STDERR.puts "Could not require '#{gem_name}', so the :#{option_name} option is now disabled."
210
+ warn "Could not require '#{gem_name}', so the :#{option_name} option is now disabled."
211
211
  true
212
212
  end
213
213
 
@@ -278,7 +278,7 @@ module JekyllImport
278
278
  end
279
279
 
280
280
  def self.process_tags(db, options, post)
281
- return [] unless options[:categories]
281
+ return [] unless options[:tags]
282
282
 
283
283
  px = options[:table_prefix]
284
284
 
@@ -266,7 +266,7 @@ module JekyllImport
266
266
  lang = "python"
267
267
  start = i
268
268
  elsif block
269
- lang = "javascript" if line =~ %r!;$!
269
+ lang = "javascript" if %r!;$!.match?(line)
270
270
  block = line =~ indent && i < lines.size - 1 # Also handle EOF
271
271
  unless block
272
272
  lines[start] = "{% highlight #{lang} %}"
@@ -283,7 +283,7 @@ module JekyllImport
283
283
  return url unless @grab_images
284
284
 
285
285
  path = "tumblr_files/#{url.split("/").last}"
286
- path += ext unless path =~ %r!#{ext}$!
286
+ path += ext unless %r!#{ext}$!.match?(path)
287
287
  FileUtils.mkdir_p "tumblr_files"
288
288
 
289
289
  # Don't fetch if we've already cached this file
@@ -55,7 +55,7 @@ module JekyllImport
55
55
  raise "Unknown database server '#{server}'"
56
56
  end
57
57
  db[SQL].each do |post|
58
- next unless post[:state] =~ %r!published!i
58
+ next unless %r!published!i.match?(post[:state])
59
59
 
60
60
  post[:slug] = "no slug" if post[:slug].nil?
61
61
 
@@ -77,8 +77,8 @@ module JekyllImport
77
77
 
78
78
  File.open("_posts/#{name}", "w") do |f|
79
79
  f.puts({ "layout" => "post",
80
- "title" => (post[:title]&.to_s&.force_encoding("UTF-8")),
81
- "tags" => (post[:keywords]&.to_s&.force_encoding("UTF-8")),
80
+ "title" => post[:title]&.to_s&.force_encoding("UTF-8"),
81
+ "tags" => post[:keywords]&.to_s&.force_encoding("UTF-8"),
82
82
  "typo_id" => post[:id], }.delete_if { |_k, v| v.nil? || v == "" }.to_yaml)
83
83
  f.puts "---"
84
84
  f.puts post[:body].delete("\r")
@@ -101,7 +101,7 @@ module JekyllImport
101
101
  begin
102
102
  require "htmlentities"
103
103
  rescue LoadError
104
- STDERR.puts "Could not require 'htmlentities', so the " \
104
+ warn "Could not require 'htmlentities', so the " \
105
105
  ":clean_entities option is now disabled."
106
106
  options[:clean_entities] = false
107
107
  end
@@ -30,14 +30,15 @@ module JekyllImport
30
30
  images.each do |i|
31
31
  uri = i["src"]
32
32
 
33
- i["src"] = format("{{ site.baseurl }}/%s/%s", assets_folder, File.basename(uri))
34
33
  dst = File.join(assets_folder, File.basename(uri))
34
+ i["src"] = File.join("{{ site.baseurl }}", dst)
35
35
  Jekyll.logger.info uri
36
36
  if File.exist?(dst)
37
37
  Jekyll.logger.info "Already in cache. Clean assets folder if you want a redownload."
38
38
  next
39
39
  end
40
40
  begin
41
+ FileUtils.mkdir_p assets_folder
41
42
  OpenURI.open_uri(uri, :allow_redirections => :safe) do |f|
42
43
  File.open(dst, "wb") do |out|
43
44
  out.puts f.read
@@ -191,7 +192,16 @@ module JekyllImport
191
192
  content = Hpricot(item.text_for("content:encoded"))
192
193
  header["excerpt"] = item.excerpt if item.excerpt
193
194
 
194
- download_images(item.title, content, assets_folder) if fetch
195
+ if fetch
196
+ # Put the images into a /yyyy/mm/ subfolder to reduce clashes
197
+ assets_dir_path = if item.published_at
198
+ File.join(assets_folder, item.published_at.strftime("/%Y/%m"))
199
+ else
200
+ assets_folder
201
+ end
202
+
203
+ download_images(item.title, content, assets_dir_path)
204
+ end
195
205
 
196
206
  FileUtils.mkdir_p item.directory_name
197
207
  File.open(File.join(item.directory_name, item.file_name), "w") do |f|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllImport
4
- VERSION = "0.18.0"
4
+ VERSION = "0.20.0"
5
5
  end
@@ -64,7 +64,7 @@ module Jekyll
64
64
 
65
65
  def abort_on_invalid_migrator(migrator)
66
66
  warn "Sorry, '#{migrator}' isn't a valid migrator. Valid choices:"
67
- IMPORTERS.keys.each { |k| warn "* #{k}" }
67
+ IMPORTERS.each_key { |k| warn "* #{k}" }
68
68
  raise "'#{migrator}' is not a valid migrator."
69
69
  end
70
70
  end
metadata CHANGED
@@ -1,38 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner
8
8
  - Parker Moore
9
9
  - Matt Rogers
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-03-22 00:00:00.000000000 Z
13
+ date: 2020-09-08 00:00:00.000000000 Z
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: fastercsv
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - "~>"
20
- - !ruby/object:Gem::Version
21
- version: '1.0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - "~>"
27
- - !ruby/object:Gem::Version
28
- version: '1.0'
29
15
  - !ruby/object:Gem::Dependency
30
16
  name: jekyll
31
17
  requirement: !ruby/object:Gem::Requirement
32
18
  requirements:
33
- - - "~>"
19
+ - - ">="
34
20
  - !ruby/object:Gem::Version
35
- version: 4.0.0.pre.alpha1
21
+ version: '3.7'
36
22
  - - "<"
37
23
  - !ruby/object:Gem::Version
38
24
  version: '5.0'
@@ -40,9 +26,9 @@ dependencies:
40
26
  prerelease: false
41
27
  version_requirements: !ruby/object:Gem::Requirement
42
28
  requirements:
43
- - - "~>"
29
+ - - ">="
44
30
  - !ruby/object:Gem::Version
45
- version: 4.0.0.pre.alpha1
31
+ version: '3.7'
46
32
  - - "<"
47
33
  - !ruby/object:Gem::Version
48
34
  version: '5.0'
@@ -164,14 +150,14 @@ dependencies:
164
150
  requirements:
165
151
  - - "~>"
166
152
  - !ruby/object:Gem::Version
167
- version: '0.4'
153
+ version: 0.11.0
168
154
  type: :development
169
155
  prerelease: false
170
156
  version_requirements: !ruby/object:Gem::Requirement
171
157
  requirements:
172
158
  - - "~>"
173
159
  - !ruby/object:Gem::Version
174
- version: '0.4'
160
+ version: 0.11.0
175
161
  - !ruby/object:Gem::Dependency
176
162
  name: shoulda
177
163
  requirement: !ruby/object:Gem::Requirement
@@ -370,6 +356,7 @@ files:
370
356
  - lib/jekyll-import/importers/behance.rb
371
357
  - lib/jekyll-import/importers/blogger.rb
372
358
  - lib/jekyll-import/importers/csv.rb
359
+ - lib/jekyll-import/importers/dotclear.rb
373
360
  - lib/jekyll-import/importers/drupal6.rb
374
361
  - lib/jekyll-import/importers/drupal7.rb
375
362
  - lib/jekyll-import/importers/drupal_common.rb
@@ -383,6 +370,7 @@ files:
383
370
  - lib/jekyll-import/importers/marley.rb
384
371
  - lib/jekyll-import/importers/mephisto.rb
385
372
  - lib/jekyll-import/importers/mt.rb
373
+ - lib/jekyll-import/importers/pluxml.rb
386
374
  - lib/jekyll-import/importers/posterous.rb
387
375
  - lib/jekyll-import/importers/roller.rb
388
376
  - lib/jekyll-import/importers/rss.rb
@@ -400,7 +388,7 @@ homepage: http://github.com/jekyll/jekyll-import
400
388
  licenses:
401
389
  - MIT
402
390
  metadata: {}
403
- post_install_message:
391
+ post_install_message:
404
392
  rdoc_options:
405
393
  - "--charset=UTF-8"
406
394
  require_paths:
@@ -417,7 +405,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
417
405
  version: '0'
418
406
  requirements: []
419
407
  rubygems_version: 3.0.3
420
- signing_key:
408
+ signing_key:
421
409
  specification_version: 4
422
410
  summary: Import command for Jekyll (static site generator).
423
411
  test_files: []