sutty-migration 0.3.2 → 0.3.4
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1f1e56381a9e282ccff520293e16f0e8db930dc2f42d677a9e0d009f2d94e09
|
4
|
+
data.tar.gz: 52ea0428940d4cd225fdbb7fc94fc110a6a6c070fe9e760027f4435f6eb92e22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78b02124119406fa7357c7c2abf22e36dfab4297d2d8a6c7ed78c3ac438a0812da6f36e34f1ae332ef5282d8f5844e3090eb3e98e76cf40cdd3c4b6f25dafa6f
|
7
|
+
data.tar.gz: e5749eeca2cec6462e73e8a8acd288685a8aaa2fc7c841cc2f3824af5d97faac2f6ae6fe359ebdfc5ebdcfc8257c682c07ef10f7e0b18896f139fb77dbca5e82
|
@@ -24,14 +24,15 @@ module SuttyMigration
|
|
24
24
|
collection = site.collections[collection] if collection.is_a? String
|
25
25
|
slug = ::Jekyll::Utils.slugify(title, mode: 'latin') if slug.blank?
|
26
26
|
basename = "#{date.strftime('%F')}-#{slug}.markdown"
|
27
|
-
path = File.join(collection.
|
27
|
+
path = File.join(collection.relative_directory, basename)
|
28
28
|
|
29
29
|
raise DocumentExists, "#{path} already exists" if File.exist? path
|
30
30
|
|
31
|
-
|
32
|
-
collection.
|
33
|
-
|
34
|
-
|
31
|
+
indexed_documents_by_relative_path(site)[path] =
|
32
|
+
::Jekyll::Document.new(path, site: site, collection: collection).tap do |document|
|
33
|
+
collection.docs << document
|
34
|
+
document.data['title'] = title
|
35
|
+
end
|
35
36
|
end
|
36
37
|
|
37
38
|
# Finds a document by its relative path or creates it if it
|
@@ -229,8 +229,8 @@ module SuttyMigration
|
|
229
229
|
#{', f.front_matter as front_matter' if with_meta}
|
230
230
|
#{', t.terms as terms' if with_meta}
|
231
231
|
from #{prefix}posts as p
|
232
|
-
#{"left join (#{meta_query}) as f on f.post_id = p.ID" if with_meta}
|
233
|
-
#{"left join (#{terms_query}) as t on t.post_id = p.ID" if with_meta}
|
232
|
+
#{"left join (#{meta_query(layout: layout)}) as f on f.post_id = p.ID" if with_meta}
|
233
|
+
#{"left join (#{terms_query(layout: layout)}) as t on t.post_id = p.ID" if with_meta}
|
234
234
|
#{"where p.post_type = '#{layout}'" if layout}
|
235
235
|
group by p.ID
|
236
236
|
EOQ
|
@@ -240,7 +240,7 @@ module SuttyMigration
|
|
240
240
|
# converted to arrays
|
241
241
|
#
|
242
242
|
# @return [String]
|
243
|
-
def meta_query
|
243
|
+
def meta_query(layout: nil)
|
244
244
|
<<~EOQ
|
245
245
|
select
|
246
246
|
post_id,
|
@@ -253,6 +253,7 @@ module SuttyMigration
|
|
253
253
|
from #{prefix}postmeta
|
254
254
|
group by post_id, meta_key
|
255
255
|
)
|
256
|
+
#{"where post_id in (select ID from #{prefix}posts where post_type = '#{layout}')" if layout}
|
256
257
|
group by post_id
|
257
258
|
EOQ
|
258
259
|
end
|
@@ -261,7 +262,7 @@ module SuttyMigration
|
|
261
262
|
#
|
262
263
|
# @param :layout [String] Layout name
|
263
264
|
# @return [String]
|
264
|
-
def terms_query
|
265
|
+
def terms_query(layout: nil)
|
265
266
|
<<~EOQ
|
266
267
|
select
|
267
268
|
post_id,
|
@@ -274,7 +275,8 @@ module SuttyMigration
|
|
274
275
|
from #{prefix}term_relationships as r
|
275
276
|
left join #{prefix}term_taxonomy as tt on tt.term_taxonomy_id = r.term_taxonomy_id
|
276
277
|
left join #{prefix}terms as t on t.term_id = tt.term_id
|
277
|
-
|
278
|
+
#{"where r.object_id in (select ID from #{prefix}posts where post_type = '#{layout}')" if layout}
|
279
|
+
group by r.object_id, tt.taxonomy)
|
278
280
|
group by post_id
|
279
281
|
EOQ
|
280
282
|
end
|
@@ -20,7 +20,7 @@ module SuttyMigration
|
|
20
20
|
#
|
21
21
|
# @return [String]
|
22
22
|
def dest
|
23
|
-
@dest ||= URI(attachment_url).path.sub(%r{\A/}, '')
|
23
|
+
@dest ||= CGI.unescape(URI(attachment_url).path.sub(%r{\A/}, ''))
|
24
24
|
end
|
25
25
|
|
26
26
|
# Metadata, with file information as a Hash
|
@@ -40,7 +40,7 @@ module SuttyMigration
|
|
40
40
|
def download(progress: true)
|
41
41
|
return true if File.exist? dest
|
42
42
|
|
43
|
-
::Jekyll.logger.info
|
43
|
+
::Jekyll.logger.info 'Downloading:', dest
|
44
44
|
|
45
45
|
FileUtils.mkdir_p File.dirname(dest)
|
46
46
|
|
@@ -9,6 +9,8 @@ module SuttyMigration
|
|
9
9
|
class Post
|
10
10
|
attr_reader :wordpress, :item
|
11
11
|
|
12
|
+
SLASH = '/'
|
13
|
+
|
12
14
|
# @param :wordpress [SuttyMigration::WordpressXml]
|
13
15
|
# @param :item [Nokogiri::XML::Element]
|
14
16
|
def initialize(wordpress:, item:)
|
@@ -17,7 +19,7 @@ module SuttyMigration
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def inspect
|
20
|
-
"
|
22
|
+
"#<#{self.class.name} title=\"#{title}\">"
|
21
23
|
end
|
22
24
|
|
23
25
|
# Post ID
|
@@ -31,7 +33,16 @@ module SuttyMigration
|
|
31
33
|
#
|
32
34
|
# @return [String]
|
33
35
|
def permalink
|
34
|
-
@permalink ||=
|
36
|
+
@permalink ||=
|
37
|
+
begin
|
38
|
+
p = attribute_value('link').sub(wordpress.url, '')
|
39
|
+
|
40
|
+
if !p.end_with?(SLASH) && File.extname(p).empty?
|
41
|
+
p << SLASH
|
42
|
+
end
|
43
|
+
|
44
|
+
p.squeeze(SLASH)
|
45
|
+
end
|
35
46
|
end
|
36
47
|
|
37
48
|
# Title
|
@@ -52,7 +63,7 @@ module SuttyMigration
|
|
52
63
|
#
|
53
64
|
# @return [String]
|
54
65
|
def slug
|
55
|
-
@slug ||= attribute_value('post_name')
|
66
|
+
@slug ||= attribute_value('post_name').tr(SLASH, '-').squeeze('-').sub(/\A-+/, '').sub(/-+\z/, '')
|
56
67
|
end
|
57
68
|
|
58
69
|
# Publication date.
|
@@ -70,9 +81,12 @@ module SuttyMigration
|
|
70
81
|
|
71
82
|
# Modification date.
|
72
83
|
#
|
73
|
-
# @return [Time]
|
84
|
+
# @return [Time, nil]
|
74
85
|
def last_modified_at
|
75
|
-
@last_modified_at ||=
|
86
|
+
@last_modified_at ||=
|
87
|
+
if (date = attribute_value('post_modified_gmt'))
|
88
|
+
::Jekyll::Utils.parse_date(date)
|
89
|
+
end
|
76
90
|
end
|
77
91
|
|
78
92
|
# Content as HTML, with site URL removed.
|
@@ -105,7 +119,7 @@ module SuttyMigration
|
|
105
119
|
@tags ||= item.css('category').select do |c|
|
106
120
|
c[:domain] == 'post_tag'
|
107
121
|
end.map do |c|
|
108
|
-
wordpress.tags[c[:nicename]]
|
122
|
+
wordpress.tags[c[:nicename]] || { id: 0, title: c.text.strip, slug: c[:nicename] }
|
109
123
|
end
|
110
124
|
end
|
111
125
|
|
@@ -116,7 +130,7 @@ module SuttyMigration
|
|
116
130
|
@categories ||= item.css('category').select do |c|
|
117
131
|
c[:domain] == 'category'
|
118
132
|
end.map do |c|
|
119
|
-
wordpress.categories[c[:nicename]]
|
133
|
+
wordpress.categories[c[:nicename]] || { id: 0, title: c.text.strip, slug: c[:nicename], parent: nil }
|
120
134
|
end
|
121
135
|
end
|
122
136
|
|
@@ -162,9 +176,9 @@ module SuttyMigration
|
|
162
176
|
|
163
177
|
# Get a value from the attribute
|
164
178
|
#
|
165
|
-
# @return [String]
|
179
|
+
# @return [String, nil]
|
166
180
|
def attribute_value(key)
|
167
|
-
item.at_css(key)
|
181
|
+
item.at_css(key)&.text
|
168
182
|
end
|
169
183
|
end
|
170
184
|
end
|
@@ -86,7 +86,7 @@ module SuttyMigration
|
|
86
86
|
slug: attribute_value(category, 'category_nicename')
|
87
87
|
}
|
88
88
|
}
|
89
|
-
end.reduce(&:merge)
|
89
|
+
end.reduce(&:merge) || {}
|
90
90
|
end
|
91
91
|
|
92
92
|
# Tags with attributes, indexed by slug
|
@@ -101,7 +101,7 @@ module SuttyMigration
|
|
101
101
|
slug: attribute_value(tag, 'tag_slug')
|
102
102
|
}
|
103
103
|
}
|
104
|
-
end.reduce(&:merge)
|
104
|
+
end.reduce(&:merge) || {}
|
105
105
|
end
|
106
106
|
|
107
107
|
# Posts, indexed by ID
|
@@ -146,9 +146,9 @@ module SuttyMigration
|
|
146
146
|
#
|
147
147
|
# @param [Nokogiri::XML::Element]
|
148
148
|
# @param [String]
|
149
|
-
# @return [String]
|
149
|
+
# @return [String,nil]
|
150
150
|
def attribute_value(element, attribute)
|
151
|
-
element.at_css(attribute)
|
151
|
+
element.at_css(attribute)&.text
|
152
152
|
end
|
153
153
|
end
|
154
154
|
end
|
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.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
214
|
- !ruby/object:Gem::Version
|
215
215
|
version: '0'
|
216
216
|
requirements: []
|
217
|
-
rubygems_version: 3.
|
217
|
+
rubygems_version: 3.3.27
|
218
218
|
signing_key:
|
219
219
|
specification_version: 4
|
220
220
|
summary: Jekyll data migration for Sutty
|