jekyll-images 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll/filters/thumbnail.rb +21 -9
- data/lib/jekyll/images/thumbnail.rb +13 -6
- metadata +5 -6
- data/lib/jekyll/hooks/thumbnail.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ade8806597db4aad25430a39bb1c7a8db08e4e474015344e7afe2e8bbd717038
|
4
|
+
data.tar.gz: c97d3622656034a395f745aaeafe47fc994cb1c1a18ba9853251ef77f924ebcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3398cc500da4c3ee7ea3be463247422636e37d9a363ab5b2aa94a42acd755f90341995c35b51055fe6bb446b90526a383d3bffbb507cbde64750b98cb85ac94c
|
7
|
+
data.tar.gz: b76bdd36d899533d031990eb152bb93032e609877b32806b9a629c6c4590ddef5baae6e63e8f98a236574d3a21d0fb10538c64ac8d7fee7b64e92af55418c1a6
|
@@ -1,29 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'pry'
|
3
4
|
module Jekyll
|
4
5
|
module Filters
|
5
6
|
# Liquid filter for use in templates
|
6
7
|
module Thumbnail
|
8
|
+
@@cached_images = {}
|
9
|
+
|
7
10
|
# Generates a thumbnail and returns its alternate destination
|
8
11
|
def thumbnail(input, width, height = nil, crop = :attention, auto_rotate = true)
|
9
12
|
return unless input
|
13
|
+
return cached_image(input).dest if cached_image? input
|
10
14
|
|
11
15
|
height = height if height.to_i > 1
|
12
|
-
image =
|
13
|
-
|
14
|
-
width: width,
|
15
|
-
height: height,
|
16
|
-
crop: crop,
|
17
|
-
auto_rotate: auto_rotate)
|
18
|
-
|
19
|
-
# XXX: This won't run optimizations more than once but it won't
|
20
|
-
# also optimize source images.
|
16
|
+
image = cached_image input, width, height, crop, auto_rotate
|
17
|
+
|
21
18
|
image.write && image.optimize
|
22
19
|
image.dest
|
23
20
|
rescue Vips::Error => e
|
24
21
|
Jekyll.logger.warn "Failed to process #{input}: #{e.message}"
|
25
22
|
input
|
26
23
|
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def cached_image?(input)
|
28
|
+
@@cached_images.key? input
|
29
|
+
end
|
30
|
+
|
31
|
+
def cached_image(input, width = nil, height = nil, crop = nil, auto_rotate = nil)
|
32
|
+
@@cached_images[input] ||= Jekyll::Images::Thumbnail.new(@context.registers[:site],
|
33
|
+
input,
|
34
|
+
width: width,
|
35
|
+
height: height,
|
36
|
+
crop: crop,
|
37
|
+
auto_rotate: auto_rotate)
|
38
|
+
end
|
27
39
|
end
|
28
40
|
end
|
29
41
|
end
|
@@ -47,14 +47,17 @@ module Jekyll
|
|
47
47
|
|
48
48
|
# Generates a destination from filename only if we're downsizing
|
49
49
|
def dest
|
50
|
-
@dest ||= if
|
50
|
+
@dest ||= if thumbnail?
|
51
51
|
filename.gsub(/#{extname}\z/, "_#{width}x#{height}#{extname}")
|
52
52
|
else
|
53
|
-
|
54
|
-
filename
|
53
|
+
filename.gsub(/#{extname}\z/, "_optimized#{extname}")
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
57
|
+
def thumbnail?
|
58
|
+
image.width > width
|
59
|
+
end
|
60
|
+
|
58
61
|
def extname
|
59
62
|
@extname ||= File.extname filename
|
60
63
|
end
|
@@ -69,8 +72,12 @@ module Jekyll
|
|
69
72
|
def write
|
70
73
|
return unless write?
|
71
74
|
|
72
|
-
|
73
|
-
|
75
|
+
if thumbnail?
|
76
|
+
Jekyll.logger.info "Thumbnailing #{filename} => #{dest}"
|
77
|
+
thumbnail.write_to_file(dest)
|
78
|
+
else
|
79
|
+
FileUtils.cp(filename, dest)
|
80
|
+
end
|
74
81
|
|
75
82
|
# Add it to the static files so Jekyll copies them. Once they
|
76
83
|
# are written they're copied when the site is loaded.
|
@@ -90,7 +97,7 @@ module Jekyll
|
|
90
97
|
|
91
98
|
pct = ((after.to_f / before) * -100 + 100).round(2)
|
92
99
|
|
93
|
-
Jekyll.logger.info "Reduced #{
|
100
|
+
Jekyll.logger.info "Reduced #{dest} from #{before} to #{after} bytes (%#{pct})"
|
94
101
|
end
|
95
102
|
end
|
96
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-images
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -65,7 +65,6 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- lib/jekyll-images.rb
|
67
67
|
- lib/jekyll/filters/thumbnail.rb
|
68
|
-
- lib/jekyll/hooks/thumbnail.rb
|
69
68
|
- lib/jekyll/images/jpeg_optim.rb
|
70
69
|
- lib/jekyll/images/oxipng.rb
|
71
70
|
- lib/jekyll/images/runner.rb
|
@@ -78,7 +77,7 @@ metadata:
|
|
78
77
|
homepage_uri: https://0xacab.org/sutty/jekyll/jekyll-images
|
79
78
|
source_code_uri: https://0xacab.org/sutty/jekyll/jekyll-images
|
80
79
|
documentation_uri: https://rubydoc.info/gems/jekyll-images
|
81
|
-
post_install_message:
|
80
|
+
post_install_message:
|
82
81
|
rdoc_options:
|
83
82
|
- "--title"
|
84
83
|
- jekyll-images - Optimizes images for Jekyll
|
@@ -101,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
100
|
version: '0'
|
102
101
|
requirements: []
|
103
102
|
rubygems_version: 3.0.3
|
104
|
-
signing_key:
|
103
|
+
signing_key:
|
105
104
|
specification_version: 4
|
106
105
|
summary: Optimizes images for Jekyll
|
107
106
|
test_files: []
|