jekyll-images 0.2.6.1 → 0.3.1
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/image.rb +7 -5
- data/lib/jekyll/images/thumbnail.rb +20 -8
- 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: 2b9b71c35193e6576d44fe7acab6166e90c5e9a55c6b884d3fd63d1bbd9af5e2
|
4
|
+
data.tar.gz: ad1a2f6f0913b44b5e7e0f824ea547fcdb37a940c7b4b5aeb7582407b4638c82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5be91d54ad4e4c410581044f6446040098e8999a845ed5545a68f9c3dfb19a9a9a0bf81de3f9ae84195e9876d4b862a70613ef0b370f2641152bab63211be3c4
|
7
|
+
data.tar.gz: 93dc21ef593b4c334f8288ff93b4a957397ff435003b1621fb1145235c50096ccb0676e8530c66ecdc406f5fa8337d8bf88bf175d753a68dbd8c7d94561c29bb
|
@@ -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? input
|
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
|
data/lib/jekyll/images/image.rb
CHANGED
@@ -5,7 +5,7 @@ require 'vips'
|
|
5
5
|
module Jekyll
|
6
6
|
module Images
|
7
7
|
class Image
|
8
|
-
attr_reader :site, :filename
|
8
|
+
attr_reader :site, :filename, :height, :width
|
9
9
|
|
10
10
|
def initialize(site, filename)
|
11
11
|
unless File.exist? filename
|
@@ -15,14 +15,16 @@ module Jekyll
|
|
15
15
|
@cached_thumbnails = {}
|
16
16
|
@site = site
|
17
17
|
@filename = filename
|
18
|
-
end
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
# We only need the image to get height and width
|
20
|
+
image = Vips::Image.new_from_file filename, access: :sequential
|
21
|
+
|
22
|
+
@height = image.height
|
23
|
+
@width = image.width
|
22
24
|
end
|
23
25
|
|
24
26
|
def thumbnail(**args)
|
25
|
-
@cached_thumbnails[args.hash.to_s] ||= Thumbnail.new site: site, filename: filename, image:
|
27
|
+
@cached_thumbnails[args.hash.to_s] ||= Thumbnail.new site: site, filename: filename, image: self, **args
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
@@ -21,12 +21,14 @@ module Jekyll
|
|
21
21
|
@auto_rotate = args[:auto_rotate].nil? ? true : args[:auto_rotate]
|
22
22
|
end
|
23
23
|
|
24
|
+
# XXX: We don't memoize because we don't need the thumbnail in
|
25
|
+
# memory after it has been written.
|
24
26
|
def thumbnail
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
Vips::Image.thumbnail filename,
|
28
|
+
width,
|
29
|
+
height: height,
|
30
|
+
auto_rotate: auto_rotate,
|
31
|
+
crop: crop
|
30
32
|
end
|
31
33
|
|
32
34
|
# Finds a height that's proportional to the width
|
@@ -48,6 +50,10 @@ module Jekyll
|
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
53
|
+
def url
|
54
|
+
static_file.url
|
55
|
+
end
|
56
|
+
|
51
57
|
def thumbnail?
|
52
58
|
image.width > width
|
53
59
|
end
|
@@ -76,9 +82,7 @@ module Jekyll
|
|
76
82
|
|
77
83
|
# Add it to the static files so Jekyll copies them. Once they
|
78
84
|
# are written they're copied when the site is loaded.
|
79
|
-
site.static_files <<
|
80
|
-
File.dirname(dest),
|
81
|
-
File.basename(dest))
|
85
|
+
site.static_files << static_file
|
82
86
|
|
83
87
|
# The file was updated, so it exists and is newer than source
|
84
88
|
!write?
|
@@ -94,6 +98,14 @@ module Jekyll
|
|
94
98
|
|
95
99
|
Jekyll.logger.info "Reduced #{dest} from #{before} to #{after} bytes (%#{pct})"
|
96
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
|
97
109
|
end
|
98
110
|
end
|
99
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.
|
4
|
+
version: 0.3.1
|
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-02-25 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
|