jekyll-images 0.3.0 → 0.4.0rc0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 940d7564e5f46ba24c22eec51f474252fc5f23445f37f2589a05788c2b107e55
4
- data.tar.gz: 3fdb9012e009324edac12a65d2550dedb93cb4bf899d50ce011a0849c23fc44a
3
+ metadata.gz: 7b806091563d3dfe022d4e6558631c998aa1be7cec781363b15a957bfbf09bc2
4
+ data.tar.gz: f7732fba18d8ed4e84b8c6f944ef1bc857d67ea2ad704e7d0522c54ff708709a
5
5
  SHA512:
6
- metadata.gz: f1b872ea8903b49b10efe560c0d568debcdfb937a8efbdb6059f238251ab71279d78056479d756cbc7c6bef34577e23c09e22c0ce97ff73d1e2ec0e853b31a49
7
- data.tar.gz: 59136867e0841097770b5ae7f3a774f8a4d6934445dcc0bf8e47ab6df4104bd70d34061eb88ac0bcf0c7ef6c53a4b30c970f959164700a41cb4a501008593772
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,14 +6,14 @@ module Jekyll
6
6
  module Height
7
7
  def height(input)
8
8
  return unless input
9
- input = @context.registers[:site].in_source_dir input
9
+ path = @context.registers[:site].in_source_dir input
10
10
 
11
- unless ::File.exist? input
11
+ unless ::File.exist? path
12
12
  Jekyll.logger.warn "File doesn't exist #{input}"
13
13
  return input
14
14
  end
15
15
 
16
- Jekyll::Images::Cache.cached_image(input).height
16
+ Jekyll::Images::Cache.cached_image(path).height
17
17
  rescue Vips::Error => e
18
18
  Jekyll.logger.warn "Failed to process #{input}: #{e.message}"
19
19
  nil
@@ -6,15 +6,17 @@ 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
10
- input = @context.registers[:site].in_source_dir input
9
+ return input unless input
10
+ return input unless Jekyll.env == 'production'
11
11
 
12
- unless ::File.exist? input
12
+ path = @context.registers[:site].in_source_dir input
13
+
14
+ unless ::File.exist? path
13
15
  Jekyll.logger.warn "File doesn't exist #{input}"
14
16
  return input
15
17
  end
16
18
 
17
- image = Jekyll::Images::Cache.cached_image input
19
+ image = Jekyll::Images::Cache.cached_image path
18
20
  thumb = image.thumbnail(width: width,
19
21
  height: height,
20
22
  crop: crop,
@@ -6,14 +6,14 @@ module Jekyll
6
6
  module Width
7
7
  def width(input)
8
8
  return unless input
9
- input = @context.registers[:site].in_source_dir input
9
+ path = @context.registers[:site].in_source_dir input
10
10
 
11
- unless ::File.exist? input
11
+ unless ::File.exist? path
12
12
  Jekyll.logger.warn "File doesn't exist #{input}"
13
13
  return input
14
14
  end
15
15
 
16
- Jekyll::Images::Cache.cached_image(input).width
16
+ Jekyll::Images::Cache.cached_image(path).width
17
17
  rescue Vips::Error => e
18
18
  Jekyll.logger.warn "Failed to process #{input}: #{e.message}"
19
19
  nil
@@ -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
data/lib/jekyll-images.rb CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  require_relative 'jekyll/images/cache'
4
4
 
5
- Jekyll::Images::Cache.site = Jekyll.sites.first
5
+ Jekyll::Hooks.register :site, :after_reset do |site|
6
+ Jekyll::Images::Cache.site = site
7
+ end
6
8
 
7
9
  require_relative 'jekyll/images/image'
8
10
  require_relative 'jekyll/images/thumbnail'
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.0
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: 2021-11-16 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,11 +99,11 @@ 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
- rubygems_version: 3.1.2
106
+ rubygems_version: 3.1.6
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Optimizes images for Jekyll