jekyll-import 0.15.0 → 0.16.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: 5dc36b6cb2508c37bc5af40022d3a56f75c5ccaf1ae60ab631db9986f4d0a799
4
- data.tar.gz: c0ab3fd214f121e75e5388143344a2c5501d2e81e1205db004c8510c01e2ae1c
3
+ metadata.gz: 6130f83944ddf0b9014aadff407cbd2645a7fd3af8ffff14f8a07f951ca36b1d
4
+ data.tar.gz: f1a0359e7d7edce0dcfbca231febe10df7459cba5f2af3ad0a2cb8f63c2fc1bc
5
5
  SHA512:
6
- metadata.gz: c0701c36d3cf270e612e1d8292447b870e3c6a3db0904d57b8f3c5a4fedb195fa6586aa840e666b325fc291f15fca95d1a17fe05e6556a95ef59c7128784e732
7
- data.tar.gz: 5355d89fbe103c753cc9b48ac6d3f398e6a980a1a86a0e19e69ba0e8cc3967a188db6ba45eb515e3a711a2e55b23f768c3b3583534b6ec8760010828bc855c8b
6
+ metadata.gz: 3650b1cc1cedfa296c5bb0b8db5fe172d32d8f67168554280a5674deb25a0595e5005288a3a2faefb01cbc109c994f41ee7477cd09c3947f4e3db68782b924ab
7
+ data.tar.gz: 3cd40ad126a4890d2dde5b84f2bef3dc6be9d4f07465a42669fe5c4e3137ac57965e32a2182ddbdc8ab1847082a166a6462e4d53675682383991f23968ba8219
@@ -139,9 +139,7 @@ module JekyllImport
139
139
  if attrs["rel"] == "alternate" && attrs["type"] == "text/html"
140
140
  @in_entry_elem[:meta][:original_url] = attrs["href"]
141
141
  elsif attrs["rel"] == "replies" && attrs["type"] == "text/html"
142
- unless @in_entry_elem[:meta][:original_url]
143
- @in_entry_elem[:meta][:original_url] = attrs["href"].sub(%r!\#comment-form$!, "")
144
- end
142
+ @in_entry_elem[:meta][:original_url] = attrs["href"].sub(%r!\#comment-form$!, "") unless @in_entry_elem[:meta][:original_url]
145
143
  end
146
144
  end
147
145
  when "media:thumbnail"
@@ -56,11 +56,11 @@ module JekyllImport
56
56
  prefix = options.fetch("prefix", DEFAULTS["prefix"])
57
57
  types = options.fetch("types", DEFAULTS["types"])
58
58
 
59
- if engine == "postgresql"
60
- db = Sequel.postgres(dbname, :user => user, :password => pass, :host => host, :encoding => "utf8")
61
- else
62
- db = Sequel.mysql2(dbname, :user => user, :password => pass, :host => host, :port => port, :encoding => "utf8")
63
- end
59
+ db = if engine == "postgresql"
60
+ Sequel.postgres(dbname, :user => user, :password => pass, :host => host, :encoding => "utf8")
61
+ else
62
+ Sequel.mysql2(dbname, :user => user, :password => pass, :host => host, :port => port, :encoding => "utf8")
63
+ end
64
64
 
65
65
  query = build_query(prefix, types, engine)
66
66
 
@@ -7,9 +7,7 @@ module JekyllImport
7
7
  if options["marley_data_dir"].nil?
8
8
  Jekyll.logger.abort_with "Missing mandatory option --marley_data_dir."
9
9
  else
10
- unless File.directory?(options["marley_data_dir"])
11
- raise ArgumentError, "marley dir '#{options["marley_data_dir"]}' not found"
12
- end
10
+ raise ArgumentError, "marley dir '#{options["marley_data_dir"]}' not found" unless File.directory?(options["marley_data_dir"])
13
11
  end
14
12
  end
15
13
 
@@ -96,36 +96,30 @@ module JekyllImport
96
96
  :port => options[:port],
97
97
  :encoding => "utf8")
98
98
 
99
- posts_query = "
100
- SELECT
101
- weblogentry.id AS `id`,
102
- weblogentry.status AS `status`,
103
- weblogentry.title AS `title`,
104
- weblogentry.anchor AS `slug`,
105
- weblogentry.updatetime AS `date`,
106
- weblogentry.text AS `content`,
107
- weblogentry.summary AS `excerpt`,
108
- weblogentry.categoryid AS `categoryid`,
109
- roller_user.fullname AS `author`,
110
- roller_user.username AS `author_login`,
111
- roller_user.emailaddress AS `author_email`,
112
- weblog.handle AS `site`
113
- FROM weblogentry AS `weblogentry`
114
- LEFT JOIN roller_user AS `roller_user`
115
- ON weblogentry.creator = roller_user.username
116
- LEFT JOIN weblog AS `weblog`
117
- ON weblogentry.websiteid = weblog.id"
99
+ select = ["weblogentry.id AS `id`",
100
+ "weblogentry.status AS `status`",
101
+ "weblogentry.title AS `title`",
102
+ "weblogentry.anchor AS `slug`",
103
+ "weblogentry.updatetime AS `date`",
104
+ "weblogentry.text AS `content`",
105
+ "weblogentry.summary AS `excerpt`",
106
+ "weblogentry.categoryid AS `categoryid`",
107
+ "roller_user.fullname AS `author`",
108
+ "roller_user.username AS `author_login`",
109
+ "roller_user.emailaddress AS `author_email`",
110
+ "weblog.handle AS `site`",]
111
+ table = "weblogentry AS `weblogentry`"
112
+ join = ["roller_user AS `roller_user` ON weblogentry.creator = roller_user.username",
113
+ "weblog AS `weblog` ON weblogentry.websiteid = weblog.id",]
114
+ condition = []
118
115
 
119
116
  if options[:status] && !options[:status].empty?
120
- status = options[:status][0]
121
- posts_query += "
122
- WHERE weblogentry.status = '#{status}'"
123
- options[:status][1..-1].each do |stat|
124
- posts_query += " OR
125
- weblogentry.status = '#{stat}'"
117
+ options[:status].each do |stat|
118
+ condition.push("weblogentry.status = '#{stat}'")
126
119
  end
127
120
  end
128
121
 
122
+ posts_query = gen_db_query(select, table, condition, join, "OR")
129
123
  db[posts_query].each do |post|
130
124
  process_post(post, db, options)
131
125
  end
@@ -154,13 +148,10 @@ module JekyllImport
154
148
  tags = []
155
149
 
156
150
  if options[:categories]
157
- cquery =
158
- "SELECT
159
- weblogcategory.name AS `name`
160
- FROM
161
- weblogcategory AS `weblogcategory`
162
- WHERE
163
- weblogcategory.id = '#{post[:categoryid]}'"
151
+ select = "weblogcategory.name AS `name`"
152
+ table = "weblogcategory AS `weblogcategory`"
153
+ condition = "weblogcategory.id = '#{post[:categoryid]}'"
154
+ cquery = gen_db_query(select, table, condition, "", "")
164
155
 
165
156
  db[cquery].each do |term|
166
157
  categories << (options[:clean_entities] ? clean_entities(term[:name]) : term[:name])
@@ -168,13 +159,10 @@ module JekyllImport
168
159
  end
169
160
 
170
161
  if options[:tags]
171
- cquery =
172
- "SELECT
173
- roller_weblogentrytag.name AS `name`
174
- FROM
175
- roller_weblogentrytag AS `roller_weblogentrytag`
176
- WHERE
177
- roller_weblogentrytag.entryid = '#{post[:id]}'"
162
+ select = "roller_weblogentrytag.name AS `name`"
163
+ table = "roller_weblogentrytag AS `roller_weblogentrytag`"
164
+ condition = "roller_weblogentrytag.entryid = '#{post[:id]}'"
165
+ cquery = gen_db_query(select, table, condition, "", "")
178
166
 
179
167
  db[cquery].each do |term|
180
168
  tags << (options[:clean_entities] ? clean_entities(term[:name]) : term[:name])
@@ -184,17 +172,14 @@ module JekyllImport
184
172
  comments = []
185
173
 
186
174
  if options[:comments]
187
- cquery =
188
- "SELECT
189
- id AS `id`,
190
- name AS `author`,
191
- email AS `author_email`,
192
- posttime AS `date`,
193
- content AS `content`
194
- FROM roller_comment
195
- WHERE
196
- entryid = '#{post[:id]}' AND
197
- status = 'APPROVED'"
175
+ select = ["id AS `id`",
176
+ "name AS `author`",
177
+ "email AS `author_email`",
178
+ "url AS `author_url`",
179
+ "posttime AS `date`",
180
+ "content AS `content`",]
181
+ condition = ["entryid = '#{post[:id]}'", "status = 'APPROVED'"]
182
+ cquery = gen_db_query(select, "roller_comment", condition, "", "AND")
198
183
 
199
184
  db[cquery].each do |comment|
200
185
  comcontent = comment[:content].to_s
@@ -210,6 +195,7 @@ module JekyllImport
210
195
  "id" => comment[:id].to_i,
211
196
  "author" => comauthor,
212
197
  "author_email" => comment[:author_email].to_s,
198
+ "author_url" => comment[:author_url].to_s,
213
199
  "date" => comment[:date].to_s,
214
200
  "content" => comcontent,
215
201
  }
@@ -221,7 +207,7 @@ module JekyllImport
221
207
  # Get the relevant fields as a hash, delete empty fields and
222
208
  # convert to YAML for the header.
223
209
  data = {
224
- "layout" => post[:type].to_s,
210
+ "layout" => "post",
225
211
  "status" => post[:status].to_s,
226
212
  "published" => post[:status].to_s == "DRAFT" ? nil : (post[:status].to_s == "PUBLISHED"),
227
213
  "title" => title.to_s,
@@ -272,6 +258,43 @@ module JekyllImport
272
258
  def self.page_path(_page_id)
273
259
  ""
274
260
  end
261
+
262
+ def self.gen_db_query(select, table, condition, join, condition_join)
263
+ condition_join_string = if condition_join.empty?
264
+ "AND"
265
+ else
266
+ condition_join
267
+ end
268
+ select_string = if select.is_a?(Array)
269
+ select.join(",")
270
+ else
271
+ select
272
+ end
273
+ condition_string = if condition.is_a?(Array)
274
+ condition.join(" #{condition_join_string} ")
275
+ else
276
+ condition
277
+ end
278
+ join_string = if join.is_a?(Array)
279
+ join.join(" LEFT JOIN ")
280
+ else
281
+ join
282
+ end
283
+ query_select = "SELECT #{select_string}"
284
+ table_string = " FROM #{table}"
285
+ query_join = if join_string.empty?
286
+ ""
287
+ else
288
+ " LEFT JOIN #{join_string}"
289
+ end
290
+ query_condition = if condition_string.empty?
291
+ ""
292
+ else
293
+ " WHERE #{condition_string}"
294
+ end
295
+ query = "#{query_select}#{table_string}#{query_join}#{query_condition}"
296
+ query
297
+ end
275
298
  end
276
299
  end
277
300
  end
@@ -8,9 +8,7 @@ module JekyllImport
8
8
  end
9
9
 
10
10
  def self.validate(options)
11
- if options["source"].nil?
12
- abort "Missing mandatory option --source, e.g. --source \"http://blog.example.com/rss.php?version=2.0&all=1\""
13
- end
11
+ abort "Missing mandatory option --source, e.g. --source \"http://blog.example.com/rss.php?version=2.0&all=1\"" if options["source"].nil?
14
12
  end
15
13
 
16
14
  def self.require_deps
@@ -84,13 +84,9 @@ module JekyllImport
84
84
  :permalinks => opts.fetch("permalinks", false),
85
85
  }
86
86
 
87
- if options[:clean_entities]
88
- options[:clean_entities] = require_if_available("htmlentities", "clean_entities")
89
- end
87
+ options[:clean_entities] = require_if_available("htmlentities", "clean_entities") if options[:clean_entities]
90
88
 
91
- if options[:markdown]
92
- options[:markdown] = require_if_available("reverse_markdown", "markdown")
93
- end
89
+ options[:markdown] = require_if_available("reverse_markdown", "markdown") if options[:markdown]
94
90
 
95
91
  FileUtils.mkdir_p("_posts")
96
92
  FileUtils.mkdir_p("_drafts") if options[:drafts]
@@ -163,10 +163,10 @@ module JekyllImport
163
163
 
164
164
  if options[:status] && !options[:status].empty?
165
165
  status = options[:status][0]
166
- posts_query << "
166
+ +posts_query << "
167
167
  WHERE posts.post_status = '#{status}'"
168
168
  options[:status][1..-1].each do |post_status|
169
- posts_query << " OR
169
+ +posts_query << " OR
170
170
  posts.post_status = '#{post_status}'"
171
171
  end
172
172
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllImport
4
- VERSION = "0.15.0"
4
+ VERSION = "0.16.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-17 00:00:00.000000000 Z
11
+ date: 2018-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastercsv
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0.2'
131
+ version: '0.3'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0.2'
138
+ version: '0.3'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: shoulda
141
141
  requirement: !ruby/object:Gem::Requirement