jekyll-images 0.2.0 → 0.2.5
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/README.md +3 -22
- data/lib/jekyll-images.rb +0 -2
- data/lib/jekyll/filters/thumbnail.rb +24 -9
- data/lib/jekyll/images/thumbnail.rb +34 -14
- metadata +31 -72
- data/.gitignore +0 -8
- data/.travis.yml +0 -7
- data/Gemfile +0 -5
- data/Rakefile +0 -10
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/jekyll-images.gemspec +0 -40
- data/lib/jekyll/images/version.rb +0 -7
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
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Image optimization for Jekyll
|
2
2
|
|
3
3
|
This Jekyll plugin helps you optimize images by thumbnailing them to
|
4
|
-
the sizes you specify in templates
|
5
|
-
in posts and collections.
|
4
|
+
the sizes you specify in templates.
|
6
5
|
|
7
6
|
It uses [Libvips](https://libvips.github.io/libvips/) for performance
|
8
7
|
and low resource usage. It'll also cache the thumbnails so it only runs
|
@@ -70,31 +69,13 @@ Options for this filter are in the following order:
|
|
70
69
|
If you want to pass `crop` and `auto_rotate` but not `height`, just set
|
71
70
|
`height` to `0` or `''`.
|
72
71
|
|
73
|
-
### Configuration and posts
|
74
|
-
|
75
|
-
Images in a post content need to be configured globally:
|
76
|
-
|
77
|
-
```yaml
|
78
|
-
# _config.yml
|
79
|
-
images:
|
80
|
-
# These are bootstrap4 breakpoints in pixels
|
81
|
-
sizes:
|
82
|
-
- 576
|
83
|
-
- 768
|
84
|
-
- 992
|
85
|
-
- 1200
|
86
|
-
thumbnail:
|
87
|
-
width: 600
|
88
|
-
height: 0 # Leave this out for proportional thumbnailing
|
89
|
-
crop: attention # See Vips::Interesting
|
90
|
-
auto_rotate: true
|
91
|
-
```
|
92
|
-
|
93
72
|
## TODO
|
94
73
|
|
95
74
|
* Use `<picture>` and the `srcset` attribute automatically for posts
|
96
75
|
<https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture>
|
97
76
|
|
77
|
+
* Download and thumbnail images in posts and other documents.
|
78
|
+
|
98
79
|
## Contributing
|
99
80
|
|
100
81
|
Bug reports and pull requests are welcome on GitHub at
|
data/lib/jekyll-images.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'pry'
|
4
3
|
require_relative 'jekyll/images/thumbnail'
|
5
4
|
require_relative 'jekyll/filters/thumbnail'
|
6
|
-
require_relative 'jekyll/hooks/thumbnail'
|
7
5
|
require_relative 'jekyll/images/oxipng'
|
8
6
|
require_relative 'jekyll/images/jpeg_optim'
|
@@ -1,25 +1,40 @@
|
|
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
|
20
|
+
rescue Vips::Error => e
|
21
|
+
Jekyll.logger.warn "Failed to process #{input}: #{e.message}"
|
22
|
+
input
|
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)
|
23
38
|
end
|
24
39
|
end
|
25
40
|
end
|
@@ -8,7 +8,7 @@ module Jekyll
|
|
8
8
|
#
|
9
9
|
# We're assuming every image is going to be thumbnailed
|
10
10
|
class Thumbnail
|
11
|
-
attr_reader :site, :
|
11
|
+
attr_reader :site, :filename, :width, :height, :crop, :auto_rotate
|
12
12
|
|
13
13
|
def initialize(site, filename, **args)
|
14
14
|
unless File.exist? filename
|
@@ -20,28 +20,44 @@ module Jekyll
|
|
20
20
|
@filename = filename
|
21
21
|
@width = args[:width]
|
22
22
|
@height = args[:height]
|
23
|
-
@
|
24
|
-
@
|
25
|
-
height: height || proportional_height,
|
26
|
-
auto_rotate: args[:auto_rotate],
|
27
|
-
crop: args[:crop].to_sym
|
23
|
+
@crop = args[:crop].to_sym
|
24
|
+
@auto_rotate = args[:auto_rotate]
|
28
25
|
end
|
29
26
|
|
30
|
-
|
27
|
+
def image
|
28
|
+
@image ||= Vips::Image.new_from_file filename,
|
29
|
+
access: :sequential
|
30
|
+
end
|
31
|
+
|
32
|
+
def thumbnail
|
33
|
+
@thumbnail ||= image.thumbnail_image width,
|
34
|
+
height: height,
|
35
|
+
auto_rotate: auto_rotate,
|
36
|
+
crop: crop
|
37
|
+
end
|
38
|
+
|
39
|
+
def height
|
40
|
+
@height || proportional_height
|
41
|
+
end
|
42
|
+
|
43
|
+
# Finds a heigth that's proportional to the width
|
31
44
|
def proportional_height
|
32
|
-
@
|
45
|
+
@proportional_height ||= (image.height * (width / image.width.to_f)).round
|
33
46
|
end
|
34
47
|
|
35
48
|
# Generates a destination from filename only if we're downsizing
|
36
49
|
def dest
|
37
|
-
@dest ||= if
|
50
|
+
@dest ||= if thumbnail?
|
38
51
|
filename.gsub(/#{extname}\z/, "_#{width}x#{height}#{extname}")
|
39
52
|
else
|
40
|
-
|
41
|
-
filename
|
53
|
+
filename.gsub(/#{extname}\z/, "_optimized#{extname}")
|
42
54
|
end
|
43
55
|
end
|
44
56
|
|
57
|
+
def thumbnail?
|
58
|
+
image.width > width
|
59
|
+
end
|
60
|
+
|
45
61
|
def extname
|
46
62
|
@extname ||= File.extname filename
|
47
63
|
end
|
@@ -56,8 +72,12 @@ module Jekyll
|
|
56
72
|
def write
|
57
73
|
return unless write?
|
58
74
|
|
59
|
-
|
60
|
-
|
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
|
61
81
|
|
62
82
|
# Add it to the static files so Jekyll copies them. Once they
|
63
83
|
# are written they're copied when the site is loaded.
|
@@ -77,7 +97,7 @@ module Jekyll
|
|
77
97
|
|
78
98
|
pct = ((after.to_f / before) * -100 + 100).round(2)
|
79
99
|
|
80
|
-
Jekyll.logger.info "Reduced #{
|
100
|
+
Jekyll.logger.info "Reduced #{dest} from #{before} to #{after} bytes (%#{pct})"
|
81
101
|
end
|
82
102
|
end
|
83
103
|
end
|
metadata
CHANGED
@@ -1,139 +1,98 @@
|
|
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:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
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
|
-
name:
|
14
|
+
name: jekyll
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: ruby-
|
28
|
+
name: ruby-vips
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '2.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '2.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: minitest
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '5.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '5.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '10.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '10.0'
|
40
|
+
version: '2'
|
83
41
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
42
|
+
name: ruby-filemagic
|
85
43
|
requirement: !ruby/object:Gem::Requirement
|
86
44
|
requirements:
|
87
45
|
- - "~>"
|
88
46
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
90
|
-
type: :
|
47
|
+
version: '0.7'
|
48
|
+
type: :runtime
|
91
49
|
prerelease: false
|
92
50
|
version_requirements: !ruby/object:Gem::Requirement
|
93
51
|
requirements:
|
94
52
|
- - "~>"
|
95
53
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
54
|
+
version: '0.7'
|
97
55
|
description: Optimizes images for Jekyll
|
98
56
|
email:
|
99
57
|
- f@sutty.nl
|
100
58
|
executables: []
|
101
59
|
extensions: []
|
102
|
-
extra_rdoc_files:
|
60
|
+
extra_rdoc_files:
|
61
|
+
- README.md
|
62
|
+
- LICENSE
|
103
63
|
files:
|
104
|
-
- ".gitignore"
|
105
|
-
- ".travis.yml"
|
106
|
-
- Gemfile
|
107
64
|
- LICENSE
|
108
65
|
- README.md
|
109
|
-
- Rakefile
|
110
|
-
- bin/console
|
111
|
-
- bin/setup
|
112
|
-
- jekyll-images.gemspec
|
113
66
|
- lib/jekyll-images.rb
|
114
67
|
- lib/jekyll/filters/thumbnail.rb
|
115
68
|
- lib/jekyll/images/jpeg_optim.rb
|
116
69
|
- lib/jekyll/images/oxipng.rb
|
117
70
|
- lib/jekyll/images/runner.rb
|
118
71
|
- lib/jekyll/images/thumbnail.rb
|
119
|
-
- lib/jekyll/images/version.rb
|
120
72
|
homepage: https://0xacab.org/sutty/jekyll/jekyll-images
|
121
73
|
licenses:
|
122
74
|
- GPL-3.0
|
123
75
|
metadata:
|
124
|
-
|
76
|
+
bug_tracker_uri: https://0xacab.org/sutty/jekyll/jekyll-images/issues
|
125
77
|
homepage_uri: https://0xacab.org/sutty/jekyll/jekyll-images
|
126
78
|
source_code_uri: https://0xacab.org/sutty/jekyll/jekyll-images
|
127
|
-
|
128
|
-
post_install_message:
|
129
|
-
rdoc_options:
|
79
|
+
documentation_uri: https://rubydoc.info/gems/jekyll-images
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- "--title"
|
83
|
+
- jekyll-images - Optimizes images for Jekyll
|
84
|
+
- "--main"
|
85
|
+
- README.md
|
86
|
+
- "--line-numbers"
|
87
|
+
- "--inline-source"
|
88
|
+
- "--quiet"
|
130
89
|
require_paths:
|
131
90
|
- lib
|
132
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
133
92
|
requirements:
|
134
|
-
- - "
|
93
|
+
- - "~>"
|
135
94
|
- !ruby/object:Gem::Version
|
136
|
-
version: '
|
95
|
+
version: '2'
|
137
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
97
|
requirements:
|
139
98
|
- - ">="
|
@@ -141,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
100
|
version: '0'
|
142
101
|
requirements: []
|
143
102
|
rubygems_version: 3.0.3
|
144
|
-
signing_key:
|
103
|
+
signing_key:
|
145
104
|
specification_version: 4
|
146
105
|
summary: Optimizes images for Jekyll
|
147
106
|
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "jekyll/image/optimization"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/jekyll-images.gemspec
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path('lib', __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'jekyll/images/version'
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = 'jekyll-images'
|
9
|
-
spec.version = Jekyll::Images::VERSION
|
10
|
-
spec.authors = ['f']
|
11
|
-
spec.email = ['f@sutty.nl']
|
12
|
-
|
13
|
-
spec.summary = 'Optimizes images for Jekyll'
|
14
|
-
spec.description = 'Optimizes images for Jekyll'
|
15
|
-
spec.homepage = 'https://0xacab.org/sutty/jekyll/jekyll-images'
|
16
|
-
spec.license = 'GPL-3.0'
|
17
|
-
|
18
|
-
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
19
|
-
|
20
|
-
spec.metadata['homepage_uri'] = spec.homepage
|
21
|
-
spec.metadata['source_code_uri'] = spec.homepage
|
22
|
-
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
|
23
|
-
|
24
|
-
# Specify which files should be added to the gem when it is released.
|
25
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
-
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
-
end
|
29
|
-
spec.bindir = 'exe'
|
30
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = ['lib']
|
32
|
-
|
33
|
-
spec.add_dependency 'ruby-vips', '~> 2'
|
34
|
-
spec.add_dependency 'ruby-filemagic', '~> 0.7'
|
35
|
-
|
36
|
-
spec.add_development_dependency 'bundler', '~> 2.0'
|
37
|
-
spec.add_development_dependency 'minitest', '~> 5.0'
|
38
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
39
|
-
spec.add_development_dependency 'rubocop', '~> 0.74'
|
40
|
-
end
|