sutty-migration 0.2.1 → 0.2.2

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: bbc62b40240f7bdea15ea0994e1af5db0e7590a500459ca82e4727f86bb791a5
4
- data.tar.gz: '087218a58be167e9348d4314922a8985a56339b9c6dd340edbfa21be1aabc9ed'
3
+ metadata.gz: f5a175d5ab6dd98eb4bed7ac987961ce9aaae15355c3eeb8e191805a6192ae34
4
+ data.tar.gz: f677b5f7945ba06403239197798d1b37eaea975c2057734c16484a0c75204f48
5
5
  SHA512:
6
- metadata.gz: 5a6933d3c03a86aa0b469f75afa42c969bc22301672054cba60eb5256b87a4381c325e7d49fd9af1259cef0d44094c5fe78df2aec51f859446b34625b24921a5
7
- data.tar.gz: 3ce853bddcf43a8c993ef8c8f1e9601fb4da59bdf7eb58a96611baef8e6934375b4bd20e1cb67a008025e03b0c94d62772ab18f4d23550d063d6d381a1190bdd
6
+ metadata.gz: 9cb1bf01c37e40036dffdd19b14b78fbdf538af45625867eb6cbd45ab66bcb468a91b11a13ab86ca83e2d8692235ed0c6d4d919186d3a8713f9c81723c7978a6
7
+ data.tar.gz: a3fc41c535e1a028526beb8904be1a72b2eee49473e4036059e7b0d4bbeff9b8670bf20b564636709605200aeede0c928bf9c9613146339a01803d396c570c05
@@ -132,7 +132,7 @@ module SuttyMigration
132
132
  post[:date] = ::Jekyll::Utils.parse_date(post[:date]) unless post[:date].blank?
133
133
  post[:last_modified_at] = ::Jekyll::Utils.parse_date(post[:last_modified_at]) unless post[:last_modified_at].blank?
134
134
 
135
- post[:front_matter] = JSON.parse(post[:front_matter]).transform_keys(&:to_sym) unless post[:front_matter].blank?
135
+ post[:front_matter] = JSON.parse(post[:front_matter]).transform_keys(&:to_sym).transform_values { |v| v.size == 1 ? v.first : v } unless post[:front_matter].blank?
136
136
  post[:terms] = JSON.parse(post[:terms]).transform_keys(&:to_sym) unless post[:terms].blank?
137
137
  end
138
138
  end
@@ -203,16 +203,37 @@ module SuttyMigration
203
203
  p.menu_order as menu_order,
204
204
  p.post_mime_type as mime_type,
205
205
  p.comment_count as comment_count
206
- #{", json_group_object(f.meta_key, f.meta_value) as front_matter" if with_meta}
206
+ #{", f.front_matter as front_matter" if with_meta}
207
207
  #{", t.terms as terms" if with_meta}
208
208
  from #{prefix}posts as p
209
- left join #{prefix}postmeta as f on p.ID = f.post_id
209
+ #{"left join (#{meta_query}) as f on f.post_id = p.ID" if with_meta}
210
210
  #{"left join (#{terms_query(layout: layout)}) as t on t.id = p.ID" if with_meta}
211
211
  #{"where p.post_type = '#{layout}'" if layout}
212
212
  group by p.ID
213
213
  EOQ
214
214
  end
215
215
 
216
+ # Recover the post meta as a JSON object with multiple values
217
+ # converted to arrays
218
+ #
219
+ # @return [String]
220
+ def meta_query
221
+ <<~EOQ
222
+ select
223
+ post_id,
224
+ json_group_object(meta_key, json(meta_values)) as front_matter
225
+ from (
226
+ select
227
+ post_id,
228
+ meta_key,
229
+ json_group_array(meta_value) as meta_values
230
+ from #{prefix}postmeta
231
+ group by post_id, meta_key
232
+ )
233
+ group by post_id
234
+ EOQ
235
+ end
236
+
216
237
  # Term taxonomy query
217
238
  #
218
239
  # @param :layout [String] Layout name
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sutty-migration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-09 00:00:00.000000000 Z
11
+ date: 2021-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll