jekyll-images 0.2.7 → 0.3.2
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/height.rb +25 -0
- data/lib/jekyll/filters/thumbnail.rb +8 -14
- data/lib/jekyll/filters/width.rb +25 -0
- data/lib/jekyll/images/cache.rb +24 -0
- data/lib/jekyll/images/thumbnail.rb +13 -3
- data/lib/jekyll-images.rb +8 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 755e74791dbcb257c7185b5343b6252c17453a805019d679be3311f2d8e54f0d
|
4
|
+
data.tar.gz: 10fae9888bf119263b82e440f5919ad9cca6cca4bc4e677ca58d5ba359bfc14e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3a21bfbd3591495bf0498d0779b1343c41e4317ff539ea1221ac4202928de8b7fa03c988aa98565ca87199fd6e4fd22ddc648fb7d386b76acc0643c226ab2ae
|
7
|
+
data.tar.gz: c252876f3d1a4bd9e72769fab9a726776aae20a56b3b64cf45e2c599c930f857063dd575798ac44740e21ccb13565a1da4d6c74540dfaae3bbab6e76eb09a51b
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Filters
|
5
|
+
# Obtain image height
|
6
|
+
module Height
|
7
|
+
def height(input)
|
8
|
+
return unless input
|
9
|
+
path = @context.registers[:site].in_source_dir input
|
10
|
+
|
11
|
+
unless ::File.exist? path
|
12
|
+
Jekyll.logger.warn "File doesn't exist #{input}"
|
13
|
+
return input
|
14
|
+
end
|
15
|
+
|
16
|
+
Jekyll::Images::Cache.cached_image(path).height
|
17
|
+
rescue Vips::Error => e
|
18
|
+
Jekyll.logger.warn "Failed to process #{input}: #{e.message}"
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Liquid::Template.register_filter(Jekyll::Filters::Height)
|
@@ -4,13 +4,17 @@ module Jekyll
|
|
4
4
|
module Filters
|
5
5
|
# Liquid filter for use in templates
|
6
6
|
module Thumbnail
|
7
|
-
@@cached_images = {}
|
8
|
-
|
9
7
|
# Generates a thumbnail and returns its alternate destination
|
10
8
|
def thumbnail(input, width = nil, height = nil, crop = nil, auto_rotate = nil)
|
11
9
|
return unless input
|
10
|
+
path = @context.registers[:site].in_source_dir input
|
11
|
+
|
12
|
+
unless ::File.exist? path
|
13
|
+
Jekyll.logger.warn "File doesn't exist #{input}"
|
14
|
+
return input
|
15
|
+
end
|
12
16
|
|
13
|
-
image = cached_image
|
17
|
+
image = Jekyll::Images::Cache.cached_image path
|
14
18
|
thumb = image.thumbnail(width: width,
|
15
19
|
height: height,
|
16
20
|
crop: crop,
|
@@ -18,21 +22,11 @@ module Jekyll
|
|
18
22
|
|
19
23
|
thumb.write && thumb.optimize
|
20
24
|
|
21
|
-
thumb.
|
25
|
+
thumb.url
|
22
26
|
rescue Vips::Error => e
|
23
27
|
Jekyll.logger.warn "Failed to process #{input}: #{e.message}"
|
24
28
|
input
|
25
29
|
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def cached_image?(input)
|
30
|
-
@@cached_images.key? input
|
31
|
-
end
|
32
|
-
|
33
|
-
def cached_image(input)
|
34
|
-
@@cached_images[input] ||= Jekyll::Images::Image.new(@context.registers[:site], input)
|
35
|
-
end
|
36
30
|
end
|
37
31
|
end
|
38
32
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Filters
|
5
|
+
# Obtain image width
|
6
|
+
module Width
|
7
|
+
def width(input)
|
8
|
+
return unless input
|
9
|
+
path = @context.registers[:site].in_source_dir input
|
10
|
+
|
11
|
+
unless ::File.exist? path
|
12
|
+
Jekyll.logger.warn "File doesn't exist #{input}"
|
13
|
+
return input
|
14
|
+
end
|
15
|
+
|
16
|
+
Jekyll::Images::Cache.cached_image(path).width
|
17
|
+
rescue Vips::Error => e
|
18
|
+
Jekyll.logger.warn "Failed to process #{input}: #{e.message}"
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Liquid::Template.register_filter(Jekyll::Filters::Width)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Images
|
5
|
+
# Cache
|
6
|
+
class Cache
|
7
|
+
class << self
|
8
|
+
attr_accessor :site
|
9
|
+
|
10
|
+
def cached_images
|
11
|
+
@cached_images ||= {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def cached_image?(input)
|
15
|
+
cached_images.key? input
|
16
|
+
end
|
17
|
+
|
18
|
+
def cached_image(input)
|
19
|
+
cached_images[input] ||= Jekyll::Images::Image.new(site, input)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -50,6 +50,10 @@ module Jekyll
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
def url
|
54
|
+
static_file.url
|
55
|
+
end
|
56
|
+
|
53
57
|
def thumbnail?
|
54
58
|
image.width > width
|
55
59
|
end
|
@@ -78,9 +82,7 @@ module Jekyll
|
|
78
82
|
|
79
83
|
# Add it to the static files so Jekyll copies them. Once they
|
80
84
|
# are written they're copied when the site is loaded.
|
81
|
-
site.static_files <<
|
82
|
-
File.dirname(dest),
|
83
|
-
File.basename(dest))
|
85
|
+
site.static_files << static_file
|
84
86
|
|
85
87
|
# The file was updated, so it exists and is newer than source
|
86
88
|
!write?
|
@@ -96,6 +98,14 @@ module Jekyll
|
|
96
98
|
|
97
99
|
Jekyll.logger.info "Reduced #{dest} from #{before} to #{after} bytes (%#{pct})"
|
98
100
|
end
|
101
|
+
|
102
|
+
def relative_path
|
103
|
+
@relative_path ||= dest.sub(site.source, '').sub(%r{\A/}, '')
|
104
|
+
end
|
105
|
+
|
106
|
+
def static_file
|
107
|
+
@static_file ||= Jekyll::StaticFile.new(site, site.source, File.dirname(relative_path), File.basename(relative_path))
|
108
|
+
end
|
99
109
|
end
|
100
110
|
end
|
101
111
|
end
|
data/lib/jekyll-images.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'jekyll/images/cache'
|
4
|
+
|
5
|
+
Jekyll::Hooks.register :site, :after_reset do |site|
|
6
|
+
Jekyll::Images::Cache.site = site
|
7
|
+
end
|
8
|
+
|
3
9
|
require_relative 'jekyll/images/image'
|
4
10
|
require_relative 'jekyll/images/thumbnail'
|
5
11
|
require_relative 'jekyll/filters/thumbnail'
|
12
|
+
require_relative 'jekyll/filters/width'
|
13
|
+
require_relative 'jekyll/filters/height'
|
6
14
|
require_relative 'jekyll/images/oxipng'
|
7
15
|
require_relative 'jekyll/images/jpeg_optim'
|
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.3.2
|
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: 2022-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -64,7 +64,10 @@ files:
|
|
64
64
|
- LICENSE
|
65
65
|
- README.md
|
66
66
|
- lib/jekyll-images.rb
|
67
|
+
- lib/jekyll/filters/height.rb
|
67
68
|
- lib/jekyll/filters/thumbnail.rb
|
69
|
+
- lib/jekyll/filters/width.rb
|
70
|
+
- lib/jekyll/images/cache.rb
|
68
71
|
- lib/jekyll/images/image.rb
|
69
72
|
- lib/jekyll/images/jpeg_optim.rb
|
70
73
|
- lib/jekyll/images/oxipng.rb
|
@@ -100,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
103
|
- !ruby/object:Gem::Version
|
101
104
|
version: '0'
|
102
105
|
requirements: []
|
103
|
-
rubygems_version: 3.
|
106
|
+
rubygems_version: 3.1.6
|
104
107
|
signing_key:
|
105
108
|
specification_version: 4
|
106
109
|
summary: Optimizes images for Jekyll
|