jekyll-images 0.3.2 → 0.4.0rc0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 755e74791dbcb257c7185b5343b6252c17453a805019d679be3311f2d8e54f0d
4
- data.tar.gz: 10fae9888bf119263b82e440f5919ad9cca6cca4bc4e677ca58d5ba359bfc14e
3
+ metadata.gz: 7b806091563d3dfe022d4e6558631c998aa1be7cec781363b15a957bfbf09bc2
4
+ data.tar.gz: f7732fba18d8ed4e84b8c6f944ef1bc857d67ea2ad704e7d0522c54ff708709a
5
5
  SHA512:
6
- metadata.gz: d3a21bfbd3591495bf0498d0779b1343c41e4317ff539ea1221ac4202928de8b7fa03c988aa98565ca87199fd6e4fd22ddc648fb7d386b76acc0643c226ab2ae
7
- data.tar.gz: c252876f3d1a4bd9e72769fab9a726776aae20a56b3b64cf45e2c599c930f857063dd575798ac44740e21ccb13565a1da4d6c74540dfaae3bbab6e76eb09a51b
6
+ metadata.gz: bd1d4b6b7d5ece1782928ae15c9bf59dec33414ad5c2c50928a55768429400156ea6e404467ba2679a92b40c0fe7891a40bc427b93512c894699dc8ee1964c4b
7
+ data.tar.gz: 4273da19ba65f935b2f11cb1cfb06e0023fca26e4c384f9ae2a8708c5dbbdb15eb971cb90e2aa128df6565bd57b4300205e35b5a6232d45c9f3768fa70cbecf7
data/README.md CHANGED
@@ -31,8 +31,41 @@ Or install it yourself as:
31
31
 
32
32
  $ gem install jekyll-images
33
33
 
34
+ For image optimization, install packages containing `jpegoptim` and
35
+ `oxipng`.
36
+
37
+ ## Configuration
38
+
39
+ Everything is handled automatically. If image optimizers are found,
40
+ thumbnails are automatically optimized.
41
+
42
+ ### Interlaced / Progressive images
43
+
44
+ Interlaced images makes them appear to load faster, because the image
45
+ loads dimensions and gains quality as it downloads. According to
46
+ Cloudflare, at 50% download the image looks almost like the final
47
+ image[^0], even though interlaced images tend to use more disk space.
48
+
49
+ To enable interlacing, add to `_config.yml`:
50
+
51
+ ```yaml
52
+ images:
53
+ interlaced: true
54
+ ```
55
+
56
+ [^0]:
57
+ <https://blog.cloudflare.com/parallel-streaming-of-progressive-images/>
58
+
34
59
  ## Usage
35
60
 
61
+ ### Only builds on production
62
+
63
+ To perform actual thumbnailing, run `jekyll build` in production mode:
64
+
65
+ ```bash
66
+ JEKYLL_ENV=production bundle exec jekyll build
67
+ ```
68
+
36
69
  ### Liquid templates
37
70
 
38
71
  In your templates, you can use the `thumbnail` filter:
@@ -6,7 +6,9 @@ module Jekyll
6
6
  module Thumbnail
7
7
  # Generates a thumbnail and returns its alternate destination
8
8
  def thumbnail(input, width = nil, height = nil, crop = nil, auto_rotate = nil)
9
- return unless input
9
+ return input unless input
10
+ return input unless Jekyll.env == 'production'
11
+
10
12
  path = @context.registers[:site].in_source_dir input
11
13
 
12
14
  unless ::File.exist? path
@@ -9,7 +9,7 @@ module Jekyll
9
9
  BINARY = 'jpegoptim'.freeze
10
10
 
11
11
  def command
12
- [binary, '--strip-all', '--quiet', file]
12
+ [binary, '--strip-all', '--quiet', ('--all-progressive' if interlaced), file].compact
13
13
  end
14
14
  end
15
15
  end
@@ -9,7 +9,7 @@ module Jekyll
9
9
  BINARY = 'oxipng'.freeze
10
10
 
11
11
  def command
12
- [binary, '--strip', 'all', '--quiet', file]
12
+ [binary, '--strip', 'all', '--quiet', '--interlace', (interlaced ? '1' : '0'), file]
13
13
  end
14
14
  end
15
15
  end
@@ -7,7 +7,7 @@ module Jekyll
7
7
  module Images
8
8
  # Runner for optimizations
9
9
  class Runner
10
- attr_reader :binary, :bytes_after, :bytes_before, :file
10
+ attr_reader :binary, :bytes_after, :bytes_before, :file, :interlaced
11
11
 
12
12
  class << self
13
13
  # XXX: This only allows one optimization per file type, we could
@@ -28,15 +28,16 @@ module Jekyll
28
28
  @@mime.file(file, true)
29
29
  end
30
30
 
31
- def run(file)
31
+ def run(file, interlaced = false)
32
32
  type = mime(file)
33
- runners[type].new(file).run if runners[type]
33
+ runners[type].new(file, interlaced).run if runners[type]
34
34
  end
35
35
  end
36
36
 
37
- def initialize(file)
37
+ def initialize(file, interlaced = false)
38
38
  @file = file
39
39
  @bytes_before = bytes_after
40
+ @interlaced = interlaced
40
41
  end
41
42
 
42
43
  def bytes_after
@@ -90,7 +90,7 @@ module Jekyll
90
90
 
91
91
  # Run optimizations
92
92
  def optimize
93
- before, after = Runner.run(dest)
93
+ before, after = Runner.run(dest, interlaced?)
94
94
 
95
95
  return unless before
96
96
 
@@ -106,6 +106,10 @@ module Jekyll
106
106
  def static_file
107
107
  @static_file ||= Jekyll::StaticFile.new(site, site.source, File.dirname(relative_path), File.basename(relative_path))
108
108
  end
109
+
110
+ def interlaced?
111
+ site.config.dig('images', 'interlaced')
112
+ end
109
113
  end
110
114
  end
111
115
  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.3.2
4
+ version: 0.4.0rc0
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-03 00:00:00.000000000 Z
11
+ date: 2022-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -99,9 +99,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
99
  version: '2'
100
100
  required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">="
102
+ - - ">"
103
103
  - !ruby/object:Gem::Version
104
- version: '0'
104
+ version: 1.3.1
105
105
  requirements: []
106
106
  rubygems_version: 3.1.6
107
107
  signing_key: