jekyll-images 0.2.7 → 0.3.0
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/thumbnail.rb +13 -3
- data/lib/jekyll-images.rb +6 -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: 940d7564e5f46ba24c22eec51f474252fc5f23445f37f2589a05788c2b107e55
|
4
|
+
data.tar.gz: 3fdb9012e009324edac12a65d2550dedb93cb4bf899d50ce011a0849c23fc44a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1b872ea8903b49b10efe560c0d568debcdfb937a8efbdb6059f238251ab71279d78056479d756cbc7c6bef34577e23c09e22c0ce97ff73d1e2ec0e853b31a49
|
7
|
+
data.tar.gz: 59136867e0841097770b5ae7f3a774f8a4d6934445dcc0bf8e47ab6df4104bd70d34061eb88ac0bcf0c7ef6c53a4b30c970f959164700a41cb4a501008593772
|
@@ -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
|
+
input = @context.registers[:site].in_source_dir input
|
10
|
+
|
11
|
+
unless ::File.exist? input
|
12
|
+
Jekyll.logger.warn "File doesn't exist #{input}"
|
13
|
+
return input
|
14
|
+
end
|
15
|
+
|
16
|
+
Jekyll::Images::Cache.cached_image(input).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
|
+
input = @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 input
|
17
|
+
image = Jekyll::Images::Cache.cached_image input
|
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
|
+
input = @context.registers[:site].in_source_dir input
|
10
|
+
|
11
|
+
unless ::File.exist? input
|
12
|
+
Jekyll.logger.warn "File doesn't exist #{input}"
|
13
|
+
return input
|
14
|
+
end
|
15
|
+
|
16
|
+
Jekyll::Images::Cache.cached_image(input).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
|
@@ -50,6 +50,10 @@ module Jekyll
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
def url
|
54
|
+
static_file.url
|
55
|
+
end
|
56
|
+
|
53
57
|
def thumbnail?
|
54
58
|
image.width > width
|
55
59
|
end
|
@@ -78,9 +82,7 @@ module Jekyll
|
|
78
82
|
|
79
83
|
# Add it to the static files so Jekyll copies them. Once they
|
80
84
|
# are written they're copied when the site is loaded.
|
81
|
-
site.static_files <<
|
82
|
-
File.dirname(dest),
|
83
|
-
File.basename(dest))
|
85
|
+
site.static_files << static_file
|
84
86
|
|
85
87
|
# The file was updated, so it exists and is newer than source
|
86
88
|
!write?
|
@@ -96,6 +98,14 @@ module Jekyll
|
|
96
98
|
|
97
99
|
Jekyll.logger.info "Reduced #{dest} from #{before} to #{after} bytes (%#{pct})"
|
98
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
|
99
109
|
end
|
100
110
|
end
|
101
111
|
end
|
data/lib/jekyll-images.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'jekyll/images/cache'
|
4
|
+
|
5
|
+
Jekyll::Images::Cache.site = Jekyll.sites.first
|
6
|
+
|
3
7
|
require_relative 'jekyll/images/image'
|
4
8
|
require_relative 'jekyll/images/thumbnail'
|
5
9
|
require_relative 'jekyll/filters/thumbnail'
|
10
|
+
require_relative 'jekyll/filters/width'
|
11
|
+
require_relative 'jekyll/filters/height'
|
6
12
|
require_relative 'jekyll/images/oxipng'
|
7
13
|
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.0
|
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: 2021-11-16 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.2
|
104
107
|
signing_key:
|
105
108
|
specification_version: 4
|
106
109
|
summary: Optimizes images for Jekyll
|