jekyll-responsive-image 1.5.1 → 1.6.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/lib/jekyll-responsive-image/block.rb +7 -1
- data/lib/jekyll-responsive-image/config.rb +12 -1
- data/lib/jekyll-responsive-image/image_processor.rb +4 -5
- data/lib/jekyll-responsive-image/renderer.rb +5 -1
- data/lib/jekyll-responsive-image/resize_handler.rb +49 -20
- data/lib/jekyll-responsive-image/version.rb +1 -1
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6997784f689936e81a50d386893ff4bab36054dcaa2811b3be30aecf5d02c6c8
|
4
|
+
data.tar.gz: 0133f99007cd590aed90e238feecdc822e94003168455285c1e4ea65340833c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dab196e76bf72c37681e5ba3d0e87fb732c90fae7f58dc1e4db03a2bac0644345797412da9f854929a2d53b8881759e0b5cf8520a9d1c57bcaa34a2c2c6db4fe
|
7
|
+
data.tar.gz: f45b4fd482e8c75a728a3112ee4b0bbf3dc78f45c23f57bf9caeba2e830ae6d7ecba32a8634a3755545e6087a98555d01415c0b80f6f319473e2d9dc29a21a20
|
@@ -4,7 +4,13 @@ module Jekyll
|
|
4
4
|
include Jekyll::ResponsiveImage::Utils
|
5
5
|
|
6
6
|
def render(context)
|
7
|
-
|
7
|
+
content = super
|
8
|
+
|
9
|
+
if content.include?("\t")
|
10
|
+
content = content.lines.map {|line| line.gsub(/\G[\t ]/, " ")}.join("\n")
|
11
|
+
end
|
12
|
+
|
13
|
+
attributes = YAML.load(content)
|
8
14
|
Renderer.new(context.registers[:site], attributes).render_responsive_image
|
9
15
|
end
|
10
16
|
end
|
@@ -17,8 +17,19 @@ module Jekyll
|
|
17
17
|
@site = site
|
18
18
|
end
|
19
19
|
|
20
|
+
def valid_config(config)
|
21
|
+
config.has_key?('responsive_image') && config['responsive_image'].is_a?(Hash)
|
22
|
+
end
|
23
|
+
|
20
24
|
def to_h
|
21
|
-
|
25
|
+
config = {}
|
26
|
+
|
27
|
+
if valid_config(@site.config)
|
28
|
+
config = @site.config['responsive_image']
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
DEFAULTS.merge(config)
|
22
33
|
.merge(site_source: @site.source, site_dest: @site.dest)
|
23
34
|
end
|
24
35
|
end
|
@@ -6,14 +6,13 @@ module Jekyll
|
|
6
6
|
def process(image_path, config)
|
7
7
|
absolute_image_path = File.expand_path(image_path.to_s, config[:site_source])
|
8
8
|
|
9
|
-
|
9
|
+
Jekyll.logger.warn "Invalid image path specified: #{image_path.inspect}" unless File.file?(absolute_image_path)
|
10
10
|
|
11
|
-
resize_handler = ResizeHandler.new
|
12
|
-
img = Magick::Image::read(absolute_image_path).first
|
11
|
+
resize_handler = ResizeHandler.new(absolute_image_path, config)
|
13
12
|
|
14
13
|
{
|
15
|
-
original: image_hash(config, image_path,
|
16
|
-
resized: resize_handler.resize_image
|
14
|
+
original: image_hash(config, image_path, resize_handler.original_image.columns, resize_handler.original_image.rows),
|
15
|
+
resized: resize_handler.resize_image,
|
17
16
|
}
|
18
17
|
end
|
19
18
|
|
@@ -25,7 +25,11 @@ module Jekyll
|
|
25
25
|
partial = File.read(image_template)
|
26
26
|
template = Liquid::Template.parse(partial)
|
27
27
|
|
28
|
-
|
28
|
+
info = {
|
29
|
+
registers: { site: @site }
|
30
|
+
}
|
31
|
+
|
32
|
+
result = template.render!(@attributes.merge(@site.site_payload), info)
|
29
33
|
|
30
34
|
RenderCache.set(cache_key, result)
|
31
35
|
end
|
@@ -3,26 +3,39 @@ module Jekyll
|
|
3
3
|
class ResizeHandler
|
4
4
|
include ResponsiveImage::Utils
|
5
5
|
|
6
|
-
|
7
|
-
img.auto_orient! if config['auto_rotate']
|
6
|
+
attr_reader :original_image
|
8
7
|
|
8
|
+
def initialize(original_image_absolute_path, config)
|
9
|
+
@config = config
|
10
|
+
|
11
|
+
@original_image_absolute_path = original_image_absolute_path
|
12
|
+
|
13
|
+
if @config['auto_rotate']
|
14
|
+
load_full_image
|
15
|
+
@original_image.auto_orient!
|
16
|
+
else
|
17
|
+
load_image_properties_only
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def resize_image
|
9
22
|
resized = []
|
10
23
|
|
11
|
-
config['sizes'].each do |size|
|
24
|
+
@config['sizes'].each do |size|
|
12
25
|
width = size['width']
|
13
|
-
ratio = width.to_f /
|
14
|
-
height = (
|
26
|
+
ratio = width.to_f / @original_image.columns.to_f
|
27
|
+
height = (@original_image.rows.to_f * ratio).round
|
15
28
|
|
16
|
-
next unless needs_resizing?(
|
29
|
+
next unless needs_resizing?(width)
|
17
30
|
|
18
|
-
image_path =
|
19
|
-
filepath = format_output_path(config['output_path_format'], config, image_path, width, height)
|
20
|
-
resized.push(image_hash(config, filepath, width, height))
|
31
|
+
image_path = @original_image.filename.force_encoding(Encoding::UTF_8)
|
32
|
+
filepath = format_output_path(@config['output_path_format'], @config, image_path, width, height)
|
33
|
+
resized.push(image_hash(@config, filepath, width, height))
|
21
34
|
|
22
|
-
site_source_filepath = File.expand_path(filepath, config[:site_source])
|
23
|
-
site_dest_filepath = File.expand_path(filepath, config[:site_dest])
|
35
|
+
site_source_filepath = File.expand_path(filepath, @config[:site_source])
|
36
|
+
site_dest_filepath = File.expand_path(filepath, @config[:site_dest])
|
24
37
|
|
25
|
-
if config['save_to_source']
|
38
|
+
if @config['save_to_source']
|
26
39
|
target_filepath = site_source_filepath
|
27
40
|
else
|
28
41
|
target_filepath = site_dest_filepath
|
@@ -36,16 +49,22 @@ module Jekyll
|
|
36
49
|
|
37
50
|
Jekyll.logger.info "Generating #{target_filepath}"
|
38
51
|
|
39
|
-
|
40
|
-
|
52
|
+
load_full_image unless @original_image_pixels_loaded
|
53
|
+
|
54
|
+
if @config['strip']
|
55
|
+
@original_image.strip!
|
41
56
|
end
|
42
|
-
|
57
|
+
|
58
|
+
i = @original_image.scale(ratio)
|
59
|
+
|
60
|
+
quality = size['quality'] || @config['default_quality']
|
61
|
+
|
43
62
|
i.write(target_filepath) do |f|
|
44
63
|
f.interlace = i.interlace
|
45
|
-
f.quality =
|
64
|
+
f.quality = quality
|
46
65
|
end
|
47
66
|
|
48
|
-
if config['save_to_source']
|
67
|
+
if @config['save_to_source']
|
49
68
|
# Ensure the generated file is copied to the _site directory
|
50
69
|
Jekyll.logger.info "Copying resized image to #{site_dest_filepath}"
|
51
70
|
FileUtils.copy_file(site_source_filepath, site_dest_filepath)
|
@@ -54,7 +73,7 @@ module Jekyll
|
|
54
73
|
i.destroy!
|
55
74
|
end
|
56
75
|
|
57
|
-
|
76
|
+
@original_image.destroy!
|
58
77
|
|
59
78
|
resized
|
60
79
|
end
|
@@ -65,8 +84,18 @@ module Jekyll
|
|
65
84
|
Pathname.new(format % params).cleanpath.to_s
|
66
85
|
end
|
67
86
|
|
68
|
-
def needs_resizing?(
|
69
|
-
|
87
|
+
def needs_resizing?(width)
|
88
|
+
@original_image.columns > width
|
89
|
+
end
|
90
|
+
|
91
|
+
def load_full_image
|
92
|
+
@original_image = Magick::Image::read(@original_image_absolute_path).first
|
93
|
+
@original_image_pixels_loaded = true
|
94
|
+
end
|
95
|
+
|
96
|
+
def load_image_properties_only
|
97
|
+
@original_image = Magick::Image::ping(@original_image_absolute_path).first
|
98
|
+
@original_image_pixels_loaded = false
|
70
99
|
end
|
71
100
|
|
72
101
|
def ensure_output_dir_exists!(path)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-responsive-image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Wynn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '2.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '5.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '2.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '5.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rmagick
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '2.0'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '5.0'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: '2.0'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '5.0'
|
53
53
|
description: "\n Highly configurable Jekyll plugin for managing responsive images.
|
54
54
|
Automatically\n resizes images and provides a Liquid template tag for loading
|
55
55
|
the images with\n picture, img srcset, Imager.js, etc.\n "
|
@@ -89,8 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
|
-
|
93
|
-
rubygems_version: 2.7.3
|
92
|
+
rubygems_version: 3.1.2
|
94
93
|
signing_key:
|
95
94
|
specification_version: 4
|
96
95
|
summary: Responsive image management for Jekyll
|