jekyll-import 0.19.2 → 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: f6ddd22f60f79ab5fcac6c78d151803f28802b8ad59f54862e3bdb64922e32d9
4
- data.tar.gz: cdab53c2d665022bf20255ec6d63746f061dfb5bf0dcf435743b4c59db24c0d9
3
+ metadata.gz: 334724ebd0dbdc9774dd2e4799dea04dc5adaacc911d05cfc26f2a5daf23bbfa
4
+ data.tar.gz: 79a4f8c6de087aebca9f726275ebb3c234361b7341a01ce10c544ff65a0b6bac
5
5
  SHA512:
6
- metadata.gz: ed0ae1253459a1c2735808848131839fd3f76a89ecb1c732760b76196988681064e913a370a0a2753882f34f649e8af0982df764dc0618fa97ded46cee6e984d
7
- data.tar.gz: b2bde6c35679c9673aeb7bbdade9963b1b381c602e7df46fcbb8121ee9e43074e7b5d6a5013bfcc780eed8713fcda15bad3ad8ee0f373792db546cdc4376c188
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
@@ -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
 
@@ -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
@@ -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")
@@ -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.19.2"
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,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.2
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: 2020-03-07 00:00:00.000000000 Z
13
+ date: 2020-09-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jekyll
@@ -150,14 +150,14 @@ dependencies:
150
150
  requirements:
151
151
  - - "~>"
152
152
  - !ruby/object:Gem::Version
153
- version: '0.4'
153
+ version: 0.11.0
154
154
  type: :development
155
155
  prerelease: false
156
156
  version_requirements: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - "~>"
159
159
  - !ruby/object:Gem::Version
160
- version: '0.4'
160
+ version: 0.11.0
161
161
  - !ruby/object:Gem::Dependency
162
162
  name: shoulda
163
163
  requirement: !ruby/object:Gem::Requirement
@@ -370,6 +370,7 @@ files:
370
370
  - lib/jekyll-import/importers/marley.rb
371
371
  - lib/jekyll-import/importers/mephisto.rb
372
372
  - lib/jekyll-import/importers/mt.rb
373
+ - lib/jekyll-import/importers/pluxml.rb
373
374
  - lib/jekyll-import/importers/posterous.rb
374
375
  - lib/jekyll-import/importers/roller.rb
375
376
  - lib/jekyll-import/importers/rss.rb
@@ -387,7 +388,7 @@ homepage: http://github.com/jekyll/jekyll-import
387
388
  licenses:
388
389
  - MIT
389
390
  metadata: {}
390
- post_install_message:
391
+ post_install_message:
391
392
  rdoc_options:
392
393
  - "--charset=UTF-8"
393
394
  require_paths:
@@ -396,7 +397,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
396
397
  requirements:
397
398
  - - ">="
398
399
  - !ruby/object:Gem::Version
399
- version: 2.3.0
400
+ version: 2.4.0
400
401
  required_rubygems_version: !ruby/object:Gem::Requirement
401
402
  requirements:
402
403
  - - ">="
@@ -404,7 +405,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
404
405
  version: '0'
405
406
  requirements: []
406
407
  rubygems_version: 3.0.3
407
- signing_key:
408
+ signing_key:
408
409
  specification_version: 4
409
410
  summary: Import command for Jekyll (static site generator).
410
411
  test_files: []