jekyll-pig 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-pig.rb +59 -26
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd6c955e443343e3d518c3b174cb1f7dc665f810c8420f5dec7c8dfccf345f2d
|
4
|
+
data.tar.gz: 3d3c91f6ca57ecbd9acee9dd68554f7eb8ce04500008c9fb09c827f9f2cd88c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2ab7eb1ef1d385abb3f274659435f844e0db139822da055e429e449fea15b64145c5f3082be02fb13a9b1bad2c27ef7665a965173f0e839ed2c6e7fed40bd18
|
7
|
+
data.tar.gz: 5b3cb6c3c98675efe89e9f31a65b59765f66768ac4ffa51318b90ad93d5d179f45710ddf890063da9c90d798164f80274593ec6dc686fcf1a742e1742baa5de0
|
data/lib/jekyll-pig.rb
CHANGED
@@ -76,10 +76,10 @@ module JekyllPig
|
|
76
76
|
image_data
|
77
77
|
end
|
78
78
|
|
79
|
-
#
|
80
|
-
def get_images(
|
81
|
-
patterns = ['*.jpg', '*.jpeg', '*.png'].map { |ext| File.join(
|
82
|
-
Dir.glob(patterns).map { |
|
79
|
+
#get a list of image file names from a given path
|
80
|
+
def get_images(path)
|
81
|
+
patterns = ['*.jpg', '*.jpeg', '*.png'].map { |ext| File.join(path, ext) }
|
82
|
+
Dir.glob(patterns).map { |filepath| File.basename(filepath) }
|
83
83
|
end
|
84
84
|
|
85
85
|
def get_image(gallery_path, image_name)
|
@@ -128,20 +128,48 @@ module JekyllPig
|
|
128
128
|
image_html_url(gallery_name, image_data[index]['filename'])
|
129
129
|
end
|
130
130
|
|
131
|
-
#create thumbnails and fullsize image assets
|
132
|
-
def
|
133
|
-
#puts "jekyll-pig: processing " << image_name
|
131
|
+
#create thumbnails and fullsize image assets
|
132
|
+
def process_images(image_data, gallery_id, gallery_path, images)
|
134
133
|
#create thumbs
|
135
|
-
[1024, 500, 250, 100, 20]
|
134
|
+
sizes = [1024, 500, 250, 100, 20]
|
135
|
+
sizes.each { |size|
|
136
|
+
#output path for current size
|
136
137
|
size_out_path = File.join(@img_path, gallery_id, size.to_s)
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
138
|
+
FileUtils.mkdir_p size_out_path unless File.exists? size_out_path
|
139
|
+
|
140
|
+
#images that have already been processed for the current size
|
141
|
+
done_images = get_images(size_out_path)
|
142
|
+
#all images in the gallery with the ones already done taken away
|
143
|
+
todo_images = images - done_images
|
144
|
+
|
145
|
+
#function to get the source path to use for creating the given size thumbnail
|
146
|
+
#i.e. use the 500px sized images to make the 250px versions
|
147
|
+
source_for_size = -> (size) {
|
148
|
+
index = sizes.index(size)
|
149
|
+
source = gallery_path
|
150
|
+
if index != nil && index != 0
|
151
|
+
source = File.join(@img_path, gallery_id, sizes[index - 1].to_s)
|
152
|
+
end
|
153
|
+
source
|
154
|
+
}
|
155
|
+
|
156
|
+
#do the processing in a batch
|
157
|
+
mog = MiniMagick::Tool::Mogrify.new
|
158
|
+
mog.resize("x#{size}")
|
159
|
+
mog.sampling_factor('4:2:0')
|
160
|
+
mog.colorspace('RGB')
|
161
|
+
mog.interlace('Plane')
|
162
|
+
mog.strip()
|
163
|
+
mog.quality('75')
|
164
|
+
mog.path(size_out_path)
|
165
|
+
source_path = source_for_size.call(size)
|
166
|
+
todo_images.each { |todo| mog << File.join(source_path, todo) }
|
167
|
+
mog.call
|
144
168
|
}
|
169
|
+
end
|
170
|
+
|
171
|
+
#create full size html page for a given image
|
172
|
+
def process_image(image_data, gallery_id, gallery_path, image_name)
|
145
173
|
full_size_html_path = File.join(@html_path, gallery_id, image_name + ".html")
|
146
174
|
#create full size html if it doesn't exist
|
147
175
|
if not File.exists? full_size_html_path
|
@@ -231,6 +259,7 @@ module JekyllPig
|
|
231
259
|
|
232
260
|
#get image data from _data
|
233
261
|
image_data = get_image_data(gallery.name)
|
262
|
+
old_image_data = image_data.clone
|
234
263
|
|
235
264
|
#get images from gallery
|
236
265
|
images = get_images(gallery.path)
|
@@ -241,21 +270,25 @@ module JekyllPig
|
|
241
270
|
#sort image data
|
242
271
|
image_data = image_data.sort_by { |data| data['datetime'] }
|
243
272
|
|
244
|
-
#
|
273
|
+
#create thumbs
|
274
|
+
process_images(image_data, gallery.name, gallery.path, images)
|
275
|
+
|
245
276
|
images.each do |image_name|
|
246
|
-
#create
|
277
|
+
#create html assets for each image
|
247
278
|
process_image(image_data, gallery.name, gallery.path, image_name)
|
248
279
|
end
|
249
280
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
281
|
+
if image_data != old_image_data
|
282
|
+
#write image_data
|
283
|
+
File.open(File.join(@data_path, "#{gallery.name}.json"), 'w') { |file|
|
284
|
+
file.write(image_data.to_json)
|
285
|
+
}
|
286
|
+
|
287
|
+
#save this gallery's includable content
|
288
|
+
File.open(File.join(@includes_path, "#{gallery.name}.html"), 'w') { |file|
|
289
|
+
file.write(gallery_html(gallery.name, image_data))
|
290
|
+
}
|
291
|
+
end
|
259
292
|
end
|
260
293
|
end
|
261
294
|
end
|