jekyll_img 0.2.7 → 0.2.8
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/CHANGELOG.md +6 -0
- data/README.md +103 -1
- data/jekyll_img.gemspec +12 -10
- data/lib/img_builder.rb +16 -3
- data/lib/img_props.rb +1 -1
- data/lib/jekyll_img/version.rb +1 -1
- data/lib/jekyll_img.rb +3 -1
- metadata +19 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc81e3ae00a242cf25f3444f45da2f621c692d6c7ee4760a17b59e8acc672c4d
|
4
|
+
data.tar.gz: 8b10b63f09b8b586343fd7a4ccc42c205ad1618cb9b422712d2300838799ead3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97b5302cf184c4fa544498354f1a8bae327f1567c438d88a232eef174422425d9e416bd6b0568439c1df2544cfb9b534e3cf0603931e00b9b2ff6a708c00abd5
|
7
|
+
data.tar.gz: a3ebcc031fb6e63dc92073cf358a38c7092719df8fbf028a5e3376d5b3447e3a539647d0825f47a47c27b45121345c91fecd1af99fc00b1ee816906b71d9c638
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.2.8 / 2025-05-16
|
4
|
+
|
5
|
+
* An image can now be lazily loaded by providing the `lazy` keyword.
|
6
|
+
* An image can now be fetched with high priority by providing the `priority` keyword.
|
7
|
+
|
8
|
+
|
3
9
|
## 0.2.7 / 2024-09-11
|
4
10
|
|
5
11
|
* Further tweaking of the generated HTML.
|
data/README.md
CHANGED
@@ -100,6 +100,108 @@ the following would result in the same image being displayed:
|
|
100
100
|
{% img src="./images/blah" %}
|
101
101
|
```
|
102
102
|
|
103
|
+
### Lazy Loading
|
104
|
+
|
105
|
+
An image can be lazily loaded by providing the `lazy` keyword.
|
106
|
+
This feature relies upon the lazy loading capability built into all modern browsers and does not rely upon JavaScript.
|
107
|
+
|
108
|
+
From [Browser-level image lazy loading for the web](https://web.dev/articles/browser-level-image-lazy-loading#dimension-attributes)
|
109
|
+
on `web.dev`:
|
110
|
+
|
111
|
+
> While the browser loads an image, it doesn't immediately know the image's dimensions,
|
112
|
+
> unless they're explicitly specified.
|
113
|
+
> To let the browser reserve enough space on a page for images, and avoid disruptive layout shifts,
|
114
|
+
> we recommend adding width and height attributes to all tags.
|
115
|
+
>
|
116
|
+
> <img src="image.png" loading="lazy" alt="…" width="200" height="200">
|
117
|
+
Alternatively, specify their values directly in an inline style:
|
118
|
+
>
|
119
|
+
> <img src="image.png" loading="lazy" alt="…" style="height:200px; width:200px;">
|
120
|
+
|
121
|
+
This would translate to:
|
122
|
+
|
123
|
+
```html
|
124
|
+
{% img lazy
|
125
|
+
src="blah.webp"
|
126
|
+
style="height:200px; width:200px"
|
127
|
+
%}
|
128
|
+
```
|
129
|
+
|
130
|
+
Note that the image must be fetched in order for HTML `img` attributes `height='auto'` and `width='auto'` to work.
|
131
|
+
Thus lazy loading is incompatible with a dimension whose value is specified as `auto`.
|
132
|
+
This means that, for lazily loaded images,
|
133
|
+
`height` and `width` must have values that are computable without loading the image.
|
134
|
+
Because the Jekyll `img` tag's `size` attribute only specifies the `width` attribute,
|
135
|
+
and sets `height` to `auto`, it should not be used with the `lazy` keyword.
|
136
|
+
|
137
|
+
The following examples of implicit and explicit `auto` dimensions will all give problems:
|
138
|
+
|
139
|
+
```html
|
140
|
+
{% img lazy
|
141
|
+
caption="A warning will be written to the logger"
|
142
|
+
size="200px"
|
143
|
+
src="blah.webp"
|
144
|
+
%}
|
145
|
+
|
146
|
+
{% img lazy
|
147
|
+
src="blah.webp"
|
148
|
+
style="height:auto; width:200px"
|
149
|
+
%}
|
150
|
+
|
151
|
+
{% img lazy
|
152
|
+
src="blah.webp"
|
153
|
+
style="height:200px; width:auto"
|
154
|
+
%}
|
155
|
+
|
156
|
+
{% img lazy
|
157
|
+
src="blah.webp"
|
158
|
+
style="height:200px"
|
159
|
+
%}
|
160
|
+
|
161
|
+
{% img lazy
|
162
|
+
src="blah.webp"
|
163
|
+
style="width:200px"
|
164
|
+
%}
|
165
|
+
```
|
166
|
+
|
167
|
+
|
168
|
+
### High Priority Loading
|
169
|
+
|
170
|
+
An image can be fetched with high priority by providing the `priority` keyword.
|
171
|
+
|
172
|
+
Sample usage:
|
173
|
+
|
174
|
+
```html
|
175
|
+
{% img priority src="blah.webp" %}
|
176
|
+
```
|
177
|
+
|
178
|
+
The above generates an HTML `img` tag with a `fetchpriority='high'` attribute.
|
179
|
+
|
180
|
+
From [Browser-level image lazy loading for the web](https://web.dev/articles/browser-level-image-lazy-loading#loading-priority)
|
181
|
+
on `web.dev`:
|
182
|
+
|
183
|
+
> If you want to increase the fetch priority of an important image, use `fetchpriority="high"`.
|
184
|
+
>
|
185
|
+
> An image with `loading="lazy"` and `fetchpriority="high"` is still delayed while it's off-screen,
|
186
|
+
> and then fetched with a high priority when it's almost within the viewport.
|
187
|
+
> This combination isn't really necessary because the browser would likely load that image with high priority anyway.
|
188
|
+
|
189
|
+
|
190
|
+
Note that the image must be fetched in order for `img` attributes `height='auto'` and `width='auto'` to work.
|
191
|
+
This means that `height` and `width` must have values that are computable without loading
|
192
|
+
the image or lazy loading will not work properly.
|
193
|
+
Because the `img` tag's `size` attribute only specifies the `width` attribute, and sets `height` to `auto`,
|
194
|
+
it should not be used.
|
195
|
+
|
196
|
+
Sample usage combining lazy and high priority loading:
|
197
|
+
|
198
|
+
```html
|
199
|
+
{% img lazy priority
|
200
|
+
src="blah.webp"
|
201
|
+
style="height:200px; width:200px"
|
202
|
+
%}
|
203
|
+
```
|
204
|
+
|
103
205
|
|
104
206
|
## Supported Filetypes
|
105
207
|
|
@@ -226,7 +328,7 @@ Using CSS units means that large enough values could cause the image to exceed t
|
|
226
328
|
|
227
329
|
## Installation
|
228
330
|
|
229
|
-
Add this line to your Jekyll project's Gemfile
|
331
|
+
Add this line to your Jekyll project's `Gemfile`, within the `jekyll_plugins` group:
|
230
332
|
|
231
333
|
```ruby
|
232
334
|
group :jekyll_plugins do
|
data/jekyll_img.gemspec
CHANGED
@@ -3,11 +3,11 @@ require_relative 'lib/jekyll_img/version'
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
github = 'https://github.com/mslinn/jekyll_img'
|
5
5
|
|
6
|
-
spec.authors
|
7
|
-
spec.email
|
8
|
-
spec.files
|
6
|
+
spec.authors = ['Mike Slinn']
|
7
|
+
spec.email = ['mslinn@mslinn.com']
|
8
|
+
spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
|
9
9
|
spec.homepage = 'https://www.mslinn.com/jekyll_plugins/jekyll_img.html'
|
10
|
-
spec.license
|
10
|
+
spec.license = 'MIT'
|
11
11
|
spec.metadata = {
|
12
12
|
'allowed_push_host' => 'https://rubygems.org',
|
13
13
|
'bug_tracker_uri' => "#{github}/issues",
|
@@ -15,18 +15,20 @@ Gem::Specification.new do |spec|
|
|
15
15
|
'homepage_uri' => spec.homepage,
|
16
16
|
'source_code_uri' => github,
|
17
17
|
}
|
18
|
-
spec.name
|
18
|
+
spec.name = 'jekyll_img'
|
19
|
+
spec.platform = Gem::Platform::RUBY
|
19
20
|
spec.post_install_message = <<~END_MESSAGE
|
20
21
|
|
21
22
|
Thanks for installing #{spec.name}!
|
22
23
|
|
23
24
|
END_MESSAGE
|
24
|
-
spec.require_paths
|
25
|
+
spec.require_paths = ['lib']
|
25
26
|
spec.required_ruby_version = '>= 2.6.0'
|
26
|
-
spec.summary
|
27
|
-
spec.test_files
|
28
|
-
spec.version
|
27
|
+
spec.summary = 'Provides a Jekyll tag that generates images.'
|
28
|
+
spec.test_files = spec.files.grep %r{^(test|spec|features)/}
|
29
|
+
spec.version = JekyllImgVersion::VERSION
|
29
30
|
|
30
31
|
spec.add_dependency 'jekyll', '>= 3.5.0'
|
31
|
-
spec.add_dependency '
|
32
|
+
spec.add_dependency 'jekyll_draft', '>= 3.0.0'
|
33
|
+
spec.add_dependency 'jekyll_plugin_support', '>= 3.0.0'
|
32
34
|
end
|
data/lib/img_builder.rb
CHANGED
@@ -11,11 +11,12 @@ end
|
|
11
11
|
|
12
12
|
# Constructs HTML img tag from properties
|
13
13
|
class ImgBuilder
|
14
|
-
attr_reader :source
|
14
|
+
attr_reader :img, :props, :source
|
15
15
|
|
16
|
-
def initialize(props)
|
17
|
-
|
16
|
+
def initialize(img, props)
|
17
|
+
@img = img
|
18
18
|
@props = props
|
19
|
+
@props.compute_dependant_properties
|
19
20
|
@source = Source.new @props.src
|
20
21
|
end
|
21
22
|
|
@@ -35,12 +36,24 @@ class ImgBuilder
|
|
35
36
|
src="#{@source.src_fallback}"
|
36
37
|
#{@props.attr_style_img}
|
37
38
|
#{@props.attr_title}
|
39
|
+
#{@props.lazy}
|
40
|
+
#{@props.priority}
|
38
41
|
/>
|
39
42
|
END_IMG
|
40
43
|
end
|
41
44
|
|
42
45
|
# See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture
|
43
46
|
def generate_picture
|
47
|
+
if @props.lazy && @props.size
|
48
|
+
@img.logger.warn do
|
49
|
+
<<~END_MSG.squish
|
50
|
+
Warning: lazy loading was specified, but the size attribute was specified for the href tag
|
51
|
+
on line #{@img.line_number} (after front matter) of #{@img.page['path']}.
|
52
|
+
Specify dimensions via style or class attributes instead.
|
53
|
+
END_MSG
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
44
57
|
return generate_img if @props.src.start_with? 'http'
|
45
58
|
|
46
59
|
# avif is not well supported yet
|
data/lib/img_props.rb
CHANGED
@@ -6,7 +6,7 @@ require 'uri'
|
|
6
6
|
# All methods except compute_dependant_properties can be called in any order
|
7
7
|
class ImgProperties
|
8
8
|
attr_accessor :align, :alt, :attr_wrapper_align_class, :attribute, :attribution, :caption, :classes, :die_on_img_error,
|
9
|
-
:id, :img_display, :local_src, :nofollow, :src, :size, :style, :target, :title,
|
9
|
+
:id, :img_display, :lazy, :local_src, :nofollow, :priority, :src, :size, :style, :target, :title,
|
10
10
|
:url, :wrapper_class, :wrapper_style
|
11
11
|
|
12
12
|
SIZES = %w[eighthsize fullsize halfsize initial quartersize].freeze
|
data/lib/jekyll_img/version.rb
CHANGED
data/lib/jekyll_img.rb
CHANGED
@@ -35,7 +35,9 @@ module Jekyll
|
|
35
35
|
props.classes = @helper.parameter_specified? 'class'
|
36
36
|
props.die_on_img_error = @die_on_img_error
|
37
37
|
props.id = @helper.parameter_specified? 'id'
|
38
|
+
props.lazy = ' loading="lazy"' if @helper.parameter_specified?('lazy')
|
38
39
|
props.nofollow = @helper.parameter_specified? 'nofollow'
|
40
|
+
props.priority = ' fetchpriority="high"' if @helper.parameter_specified?('priority')
|
39
41
|
props.size = @helper.parameter_specified?('size') || @helper.parameter_specified?('_size')
|
40
42
|
props.src = @helper.parameter_specified? 'src'
|
41
43
|
props.style = @helper.parameter_specified? 'style'
|
@@ -45,7 +47,7 @@ module Jekyll
|
|
45
47
|
props.wrapper_class = @helper.parameter_specified? 'wrapper_class'
|
46
48
|
props.wrapper_style = @helper.parameter_specified? 'wrapper_style'
|
47
49
|
|
48
|
-
@builder = ImgBuilder.new(props)
|
50
|
+
@builder = ImgBuilder.new(self, props)
|
49
51
|
@builder.to_s
|
50
52
|
rescue ImgError => e # jekyll_plugin_support handles StandardError
|
51
53
|
@logger.error { e.logger_message }
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_img
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Slinn
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: jekyll
|
@@ -24,21 +23,34 @@ dependencies:
|
|
24
23
|
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: 3.5.0
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: jekyll_draft
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 3.0.0
|
27
40
|
- !ruby/object:Gem::Dependency
|
28
41
|
name: jekyll_plugin_support
|
29
42
|
requirement: !ruby/object:Gem::Requirement
|
30
43
|
requirements:
|
31
44
|
- - ">="
|
32
45
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
46
|
+
version: 3.0.0
|
34
47
|
type: :runtime
|
35
48
|
prerelease: false
|
36
49
|
version_requirements: !ruby/object:Gem::Requirement
|
37
50
|
requirements:
|
38
51
|
- - ">="
|
39
52
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
description:
|
53
|
+
version: 3.0.0
|
42
54
|
email:
|
43
55
|
- mslinn@mslinn.com
|
44
56
|
executables: []
|
@@ -89,8 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
101
|
- !ruby/object:Gem::Version
|
90
102
|
version: '0'
|
91
103
|
requirements: []
|
92
|
-
rubygems_version: 3.
|
93
|
-
signing_key:
|
104
|
+
rubygems_version: 3.6.9
|
94
105
|
specification_version: 4
|
95
106
|
summary: Provides a Jekyll tag that generates images.
|
96
107
|
test_files:
|