jekyll-gallery-generator 0.9.0 → 1.0.0
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 +4 -4
- data/README.md +17 -18
- data/jekyll-gallery-generator.gemspec +1 -1
- data/lib/gallery_page.html +3 -3
- data/lib/jekyll-gallery-generator.rb +85 -44
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcea80713b0f4630d7579d6364b8534d8f60c651
|
4
|
+
data.tar.gz: a77062b54c229259d1ca00e290f93380858a3cb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d714d25ca0673f7a8e00b53a5b68a9c56c463bace45fcd2945c8805c11612f6affca10871382449ee36898a03fe470b4c8a4d605d02373817df8a0ffa4560f42
|
7
|
+
data.tar.gz: 9f283ef8133e3063974d6dbaa6f33b7c52a25ff6746fe9ff3deff2074561f07aab8c1e071301d97c35125aa21699922f2da38b8446faf323eba059703c6448d8
|
data/README.md
CHANGED
@@ -17,14 +17,14 @@ This plugin is quite minimalist. It generates galleries with no pagination, no s
|
|
17
17
|
|
18
18
|
2. Add `jekyll-gallery-generator` to the gems list in your `_config.yml`:
|
19
19
|
|
20
|
-
```
|
20
|
+
```
|
21
21
|
gems:
|
22
22
|
- jekyll-gallery-generator
|
23
23
|
```
|
24
24
|
|
25
25
|
3. Copy your image directories into `jekyll-site/photos/`. Here's what my directory structure looks like:
|
26
26
|
|
27
|
-
```bash
|
27
|
+
```bash
|
28
28
|
$ ls jekyll-site/photos
|
29
29
|
best/ chile_trip/ japan_trip/
|
30
30
|
$ ls jekyll-site/photos/chile_trip
|
@@ -54,28 +54,27 @@ This plugin reads several config options from `_config.yml`. The following optio
|
|
54
54
|
|
55
55
|
```yaml
|
56
56
|
gallery:
|
57
|
-
#
|
58
|
-
|
59
|
-
#
|
60
|
-
|
61
|
-
#
|
62
|
-
|
63
|
-
# field to control sorting of galleries for the index page
|
64
|
-
# (possible values are: title, date_time, best_image)
|
65
|
-
sort_field: "date_time"
|
66
|
-
# sizes for thumbnails
|
57
|
+
dir: photos # Path to the gallery
|
58
|
+
symlink: false # false: copy images into _site. true: create symbolic links (saves disk space)
|
59
|
+
title: "Photos" # Title for gallery index page
|
60
|
+
title_prefix: "Photos: " # Title prefix for gallery pages. Gallery title = title_prefix + gallery_name
|
61
|
+
sort_field: "date_time" # How to sort galleries on the index page.
|
62
|
+
# Possible values are: title, date_time, best_image
|
67
63
|
thumbnail_size:
|
68
|
-
x: 400
|
69
|
-
y: 400
|
70
|
-
#
|
71
|
-
# best_image is image for the index page (defaults to last image)
|
64
|
+
x: 400 # max width of thumbnails (in pixels)
|
65
|
+
y: 400 # max height of thumbnails (in pixels)
|
66
|
+
# The following options are for individual galleries.
|
72
67
|
galleries:
|
73
68
|
chile_trip:
|
74
|
-
best_image: IMG_1068.JPG
|
69
|
+
best_image: IMG_1068.JPG # The image to show on the gallery index page. Defaults to the last image.
|
75
70
|
japan_trip:
|
76
71
|
best_image: IMG_0690.JPG
|
77
|
-
|
72
|
+
name: "日本の旅" # Defaults to directory name, replacing _ with spaces & capitalizing words.
|
73
|
+
awesome_stuff:
|
78
74
|
best_image: snaileo_gonzales.jpg
|
75
|
+
sort_reverse: true # Reverse sort images in gallery.
|
76
|
+
secret_stuff:
|
77
|
+
hidden: true # Don't show this gallery on the index page. People must guess the URL.
|
79
78
|
```
|
80
79
|
|
81
80
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "jekyll-gallery-generator"
|
3
3
|
spec.summary = "Generate galleries with thumbnails for your Jekyll site."
|
4
|
-
spec.version = "0.
|
4
|
+
spec.version = "1.0.0"
|
5
5
|
spec.authors = ["Geoff Greer"]
|
6
6
|
spec.email = "geoff@greer.fm"
|
7
7
|
spec.homepage = "https://github.com/ggreer/jekyll-gallery-generator"
|
data/lib/gallery_page.html
CHANGED
@@ -22,9 +22,9 @@ layout: page
|
|
22
22
|
<hr />
|
23
23
|
{% for image in page.images %}
|
24
24
|
<div class="gallery-image-wrapper">
|
25
|
-
<a name="{{ image }}"></a>
|
26
|
-
<a href="{{ image }}"{% if site.gallery.lightbox %} rel="lightbox[{{ page.gallery }}]"{% endif %}>
|
27
|
-
<img class="gallery-image" src="thumbs/{{ image }}" />
|
25
|
+
<a name="{{ image.name }}"></a>
|
26
|
+
<a href="{{ image.name }}"{% if site.gallery.lightbox %} rel="lightbox[{{ page.gallery }}]"{% endif %}>
|
27
|
+
<img class="gallery-image" src="thumbs/{{ image.name }}" />
|
28
28
|
</a>
|
29
29
|
</div>
|
30
30
|
{% endfor %}
|
@@ -6,18 +6,59 @@ include FileUtils
|
|
6
6
|
|
7
7
|
$image_extensions = [".png", ".jpg", ".jpeg", ".gif"]
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
module Jekyll
|
10
|
+
class GalleryImage
|
11
|
+
include Comparable
|
12
|
+
attr_accessor :name
|
13
|
+
attr_accessor :path
|
14
|
+
|
15
|
+
def initialize(name, base)
|
16
|
+
@name = name
|
17
|
+
@path = File.join(base, name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def <=>(b)
|
21
|
+
return @date_time <=> b.date_time
|
22
|
+
end
|
23
|
+
|
24
|
+
def date_time
|
25
|
+
return @date_time if defined? @date_time
|
26
|
+
begin
|
27
|
+
@date_time = self.exif.date_time.to_i
|
28
|
+
rescue Exception => e
|
29
|
+
@date_time = 0
|
30
|
+
end
|
31
|
+
return @date_time
|
32
|
+
end
|
33
|
+
|
34
|
+
def exif
|
35
|
+
return @exif if defined? @exif
|
36
|
+
@exif = nil
|
37
|
+
begin
|
38
|
+
@exif = EXIFR::JPEG.new(@path)
|
39
|
+
rescue EXIFR::MalformedJPEG
|
40
|
+
puts "No EXIF data in #{@path}"
|
41
|
+
rescue Exception => e
|
42
|
+
puts "Error reading EXIF data for #{@path}: #{e}"
|
43
|
+
end
|
44
|
+
return @exif
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
return @name
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_liquid
|
52
|
+
# Liquid hates symbol keys. Gotta stringify them
|
53
|
+
return {
|
54
|
+
'name' => @name,
|
55
|
+
'src' => @name,
|
56
|
+
'date_time' => @date_time,
|
57
|
+
'exif' => @exif && @exif.to_hash.collect{|k,v| [k.to_s, v]}.to_h,
|
58
|
+
}
|
59
|
+
end
|
16
60
|
end
|
17
|
-
return 0
|
18
|
-
end
|
19
61
|
|
20
|
-
module Jekyll
|
21
62
|
class GalleryFile < StaticFile
|
22
63
|
def write(dest)
|
23
64
|
return false
|
@@ -97,15 +138,15 @@ module Jekyll
|
|
97
138
|
scale_method = config["scale_method"] || "fit"
|
98
139
|
begin
|
99
140
|
max_size_x = config["thumbnail_size"]["x"]
|
100
|
-
rescue
|
141
|
+
rescue Exception
|
101
142
|
end
|
102
143
|
begin
|
103
144
|
max_size_y = config["thumbnail_size"]["y"]
|
104
|
-
rescue
|
145
|
+
rescue Exception
|
105
146
|
end
|
106
147
|
begin
|
107
148
|
gallery_config = config["galleries"][gallery_name] || {}
|
108
|
-
rescue
|
149
|
+
rescue Exception
|
109
150
|
end
|
110
151
|
self.process(@name)
|
111
152
|
gallery_page = File.join(base, "_layouts", "gallery_page.html")
|
@@ -115,42 +156,42 @@ module Jekyll
|
|
115
156
|
self.read_yaml(File.dirname(gallery_page), File.basename(gallery_page))
|
116
157
|
self.data["gallery"] = gallery_name
|
117
158
|
gallery_title_prefix = config["title_prefix"] || "Photos: "
|
118
|
-
gallery_name = gallery_name.gsub(
|
159
|
+
gallery_name = gallery_name.gsub(/[_-]/, " ").gsub(/\w+/) {|word| word.capitalize}
|
119
160
|
begin
|
120
161
|
gallery_name = gallery_config["name"] || gallery_name
|
121
|
-
rescue
|
162
|
+
rescue Exception
|
122
163
|
end
|
123
164
|
self.data["name"] = gallery_name
|
124
165
|
self.data["title"] = "#{gallery_title_prefix}#{gallery_name}"
|
125
|
-
|
166
|
+
self.data["exif"] = {}
|
126
167
|
begin
|
127
168
|
@hidden = gallery_config["hidden"] || false
|
128
|
-
rescue
|
169
|
+
rescue Exception
|
129
170
|
end
|
130
171
|
if @hidden
|
131
172
|
self.data["sitemap"] = false
|
132
173
|
end
|
133
174
|
|
175
|
+
thumbs_dir = File.join(site.dest, @dest_dir, "thumbs")
|
134
176
|
FileUtils.mkdir_p(thumbs_dir, :mode => 0755)
|
135
177
|
date_times = {}
|
136
178
|
entries = Dir.entries(dir)
|
137
|
-
entries.each_with_index do |
|
138
|
-
next if
|
139
|
-
next unless
|
179
|
+
entries.each_with_index do |name, i|
|
180
|
+
next if name.chars.first == "."
|
181
|
+
next unless name.downcase().end_with?(*$image_extensions)
|
182
|
+
image = GalleryImage.new(name, dir)
|
140
183
|
@images.push(image)
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
date_times[image] = get_exif_date_time(image_path)
|
184
|
+
date_times[name] = image.date_time
|
185
|
+
best_image = name
|
186
|
+
@site.static_files << GalleryFile.new(site, base, File.join(@dest_dir, "thumbs"), name)
|
146
187
|
|
147
188
|
if symlink
|
148
|
-
link_src = site.in_source_dir(
|
149
|
-
link_dest = site.in_dest_dir(
|
189
|
+
link_src = site.in_source_dir(image.path)
|
190
|
+
link_dest = site.in_dest_dir(image.path)
|
150
191
|
@site.static_files.delete_if { |sf|
|
151
|
-
sf.relative_path == "/" +
|
192
|
+
sf.relative_path == "/" + image.path
|
152
193
|
}
|
153
|
-
@site.static_files << GalleryFile.new(site, base, dir,
|
194
|
+
@site.static_files << GalleryFile.new(site, base, dir, name)
|
154
195
|
if File.exists?(link_dest) or File.symlink?(link_dest)
|
155
196
|
if not File.symlink?(link_dest)
|
156
197
|
puts "#{link_dest} exists but is not a symlink. Deleting."
|
@@ -165,16 +206,16 @@ module Jekyll
|
|
165
206
|
File.symlink(link_src, link_dest)
|
166
207
|
end
|
167
208
|
end
|
168
|
-
thumb_path = File.join(thumbs_dir,
|
169
|
-
if File.file?(thumb_path) == false or File.mtime(
|
209
|
+
thumb_path = File.join(thumbs_dir, name)
|
210
|
+
if File.file?(thumb_path) == false or File.mtime(image.path) > File.mtime(thumb_path)
|
170
211
|
begin
|
171
|
-
m_image = ImageList.new(
|
212
|
+
m_image = ImageList.new(image.path)
|
172
213
|
m_image.auto_orient!
|
173
214
|
m_image.send("resize_to_#{scale_method}!", max_size_x, max_size_y)
|
174
215
|
puts "Writing thumbnail to #{thumb_path}"
|
175
216
|
m_image.write(thumb_path)
|
176
|
-
rescue e
|
177
|
-
printf "Error generating thumbnail for #{
|
217
|
+
rescue Exception => e
|
218
|
+
printf "Error generating thumbnail for #{image.path}: #{e}\r"
|
178
219
|
puts e.backtrace
|
179
220
|
end
|
180
221
|
if i % 5 == 0
|
@@ -187,13 +228,7 @@ module Jekyll
|
|
187
228
|
puts ""
|
188
229
|
|
189
230
|
begin
|
190
|
-
@images.sort!
|
191
|
-
if date_times[a] == date_times[b]
|
192
|
-
a <=> b
|
193
|
-
else
|
194
|
-
date_times[a] <=> date_times[b]
|
195
|
-
end
|
196
|
-
}
|
231
|
+
@images.sort!
|
197
232
|
if gallery_config["sort_reverse"]
|
198
233
|
@images.reverse!
|
199
234
|
end
|
@@ -204,9 +239,15 @@ module Jekyll
|
|
204
239
|
|
205
240
|
site.static_files = @site.static_files
|
206
241
|
self.data["images"] = @images
|
207
|
-
|
208
|
-
|
209
|
-
|
242
|
+
best_image = gallery_config["best_image"] || best_image
|
243
|
+
self.data["best_image"] = best_image
|
244
|
+
if date_times.has_key?(best_image)
|
245
|
+
gallery_date_time = date_times[best_image]
|
246
|
+
else
|
247
|
+
puts "#{gallery_name}: best_image #{best_image} not found!"
|
248
|
+
gallery_date_time = 0
|
249
|
+
end
|
250
|
+
self.data["date_time"] = gallery_date_time
|
210
251
|
end
|
211
252
|
end
|
212
253
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-gallery-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoff Greer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: exifr
|