jekyll-imgflow 0.4.3 → 0.4.4
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 +7 -2
- data/interface.yml +1 -1
- data/lib/jekyll-imgflow/html_generator.rb +9 -10
- data/lib/jekyll-imgflow/intrinsic_dimensions.rb +55 -0
- data/lib/jekyll-imgflow/version.rb +1 -1
- data/lib/jekyll-imgflow.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c9496f81e064e499eed64e5b894553a4631448bb103a1f538fa10d5d16b09028
|
|
4
|
+
data.tar.gz: cb2c0d6d2fda26e79bbddcd2de701a626c0fde8a1b2cdd1e49116f25e05cfc72
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6cc5cd2ef513d558f2fc5fc84ed0170ec5bb6361907ce72212e8cf6138865dc9fddb59e1ec62880f41740f762bbdc550434145849d4f781ede0e1e22a031055f
|
|
7
|
+
data.tar.gz: 2c95809a7775802e1a0a7932b1532c04bfe8d845806c0d73859096f33e1df8062717ce59244c85d46186158c1621ff093242da97f84758ca567e39134568a0ff
|
data/README.md
CHANGED
|
@@ -143,9 +143,10 @@ rake quick # Quick checks (style + tests)
|
|
|
143
143
|
rake test # All tests
|
|
144
144
|
rake parallel:test # Parallel testing (faster)
|
|
145
145
|
|
|
146
|
-
# Docker Services
|
|
147
|
-
rake start_services # Start services
|
|
146
|
+
# Docker Services (test tasks start/stop these automatically)
|
|
147
|
+
rake start_services # Start services manually for repeated test runs
|
|
148
148
|
rake check_services # Verify services
|
|
149
|
+
rake stop_services # Stop services
|
|
149
150
|
```
|
|
150
151
|
|
|
151
152
|
**See:** [testing.md](docs/testing.md) for comprehensive testing guide, [scripts.md](docs/scripts.md) for development utilities, and [rake.md](docs/rake.md) for all available Rake tasks
|
|
@@ -184,6 +185,10 @@ imgflow:
|
|
|
184
185
|
|
|
185
186
|
## 🐳 Docker Setup (Recommended)
|
|
186
187
|
|
|
188
|
+
Test tasks that need the HTTP providers (e.g. `rake test_http_providers`)
|
|
189
|
+
start these services automatically and stop them when the run finishes.
|
|
190
|
+
Use the commands below only to keep services up across repeated runs:
|
|
191
|
+
|
|
187
192
|
```bash
|
|
188
193
|
# Start all services (pulls latest pinned images first)
|
|
189
194
|
rake start_services
|
data/interface.yml
CHANGED
|
@@ -5,6 +5,7 @@ module JekyllImgFlow
|
|
|
5
5
|
# Supports Picture Tag compatibility with multiple markup formats and attributes
|
|
6
6
|
class HtmlGenerator
|
|
7
7
|
include ModalWrapper
|
|
8
|
+
include IntrinsicDimensions
|
|
8
9
|
|
|
9
10
|
# Markup formats accepted via `markup:` (see docs/usage/tag-options.md).
|
|
10
11
|
# Unknown values fall back to `img`.
|
|
@@ -110,7 +111,7 @@ module JekyllImgFlow
|
|
|
110
111
|
# Generate standard <picture> element with <source> tags
|
|
111
112
|
def generate_picture_element
|
|
112
113
|
picture_attrs = build_attributes(@attributes[:picture])
|
|
113
|
-
img_attrs = build_img_attributes
|
|
114
|
+
img_attrs = build_img_attributes(find_fallback_image(@results))
|
|
114
115
|
|
|
115
116
|
html = "<picture#{picture_attrs}>"
|
|
116
117
|
|
|
@@ -137,8 +138,8 @@ module JekyllImgFlow
|
|
|
137
138
|
|
|
138
139
|
# Generate standard <img> element
|
|
139
140
|
def generate_img_element
|
|
140
|
-
img_attrs = build_img_attributes
|
|
141
141
|
primary = @results.first
|
|
142
|
+
img_attrs = build_img_attributes(primary)
|
|
142
143
|
|
|
143
144
|
# Build srcset if multiple results
|
|
144
145
|
srcset_attr = if @results.length > 1
|
|
@@ -154,7 +155,7 @@ module JekyllImgFlow
|
|
|
154
155
|
# Generate <picture> element with data-* attributes for lazy loading
|
|
155
156
|
def generate_data_picture_element
|
|
156
157
|
picture_attrs = build_attributes(@attributes[:picture])
|
|
157
|
-
img_attrs = build_data_img_attributes
|
|
158
|
+
img_attrs = build_data_img_attributes(find_fallback_image(@results))
|
|
158
159
|
|
|
159
160
|
html = "<picture#{picture_attrs}>"
|
|
160
161
|
|
|
@@ -181,8 +182,8 @@ module JekyllImgFlow
|
|
|
181
182
|
|
|
182
183
|
# Generate <img> element with data-* attributes for lazy loading
|
|
183
184
|
def generate_data_img_element
|
|
184
|
-
img_attrs = build_data_img_attributes
|
|
185
185
|
primary = @results.first
|
|
186
|
+
img_attrs = build_data_img_attributes(primary)
|
|
186
187
|
|
|
187
188
|
# Build data-srcset if multiple results
|
|
188
189
|
srcset_attr = if @results.length > 1
|
|
@@ -206,18 +207,16 @@ module JekyllImgFlow
|
|
|
206
207
|
end
|
|
207
208
|
|
|
208
209
|
# Build img attributes including alt, loading, and custom attributes
|
|
209
|
-
def build_img_attributes
|
|
210
|
-
attrs =
|
|
211
|
-
attrs["alt"] = @attributes[:alt] if @attributes[:alt]
|
|
210
|
+
def build_img_attributes(result = nil)
|
|
211
|
+
attrs = base_img_attrs(result)
|
|
212
212
|
attrs["loading"] = "lazy" unless attrs["loading"]
|
|
213
213
|
|
|
214
214
|
build_attributes(attrs)
|
|
215
215
|
end
|
|
216
216
|
|
|
217
217
|
# Build img attributes with data-* for lazy loading
|
|
218
|
-
def build_data_img_attributes
|
|
219
|
-
attrs =
|
|
220
|
-
attrs["alt"] = @attributes[:alt] if @attributes[:alt]
|
|
218
|
+
def build_data_img_attributes(result = nil)
|
|
219
|
+
attrs = base_img_attrs(result)
|
|
221
220
|
attrs["class"] = [attrs["class"], "lazy"].compact.join(" ")
|
|
222
221
|
|
|
223
222
|
build_attributes(attrs)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fastimage"
|
|
4
|
+
|
|
5
|
+
module JekyllImgFlow
|
|
6
|
+
# Reads a generated image file's pixel dimensions so emitted markup can
|
|
7
|
+
# carry intrinsic width/height — the browser reserves the image box before
|
|
8
|
+
# download (avoids layout shift). Mixed into HtmlGenerator.
|
|
9
|
+
module IntrinsicDimensions
|
|
10
|
+
# Emit the file's pixel dimensions unless the user supplied any.
|
|
11
|
+
# Partial overrides (e.g. only width:) would skew the aspect ratio,
|
|
12
|
+
# so both attributes are skipped together.
|
|
13
|
+
def inject_intrinsic_dimensions(attrs, result)
|
|
14
|
+
return unless result
|
|
15
|
+
return if attrs["width"] || attrs["height"]
|
|
16
|
+
|
|
17
|
+
size = intrinsic_size(result)
|
|
18
|
+
return unless size
|
|
19
|
+
|
|
20
|
+
attrs["width"] = size[0]
|
|
21
|
+
attrs["height"] = size[1]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def base_img_attrs(result = nil)
|
|
27
|
+
attrs = @attributes[:img].dup
|
|
28
|
+
attrs["alt"] = @attributes[:alt] if @attributes[:alt]
|
|
29
|
+
inject_intrinsic_dimensions(attrs, result)
|
|
30
|
+
attrs
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def intrinsic_size(result)
|
|
34
|
+
@intrinsic_sizes ||= {}
|
|
35
|
+
return @intrinsic_sizes[result] if @intrinsic_sizes.key?(result)
|
|
36
|
+
|
|
37
|
+
@intrinsic_sizes[result] = resolve_intrinsic_size(result)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def resolve_intrinsic_size(result)
|
|
41
|
+
site = @context&.registers&.dig(:site)
|
|
42
|
+
return unless site
|
|
43
|
+
|
|
44
|
+
rel = result.delete_prefix("/")
|
|
45
|
+
roots = [site.source]
|
|
46
|
+
roots << site.dest if site.respond_to?(:dest)
|
|
47
|
+
path = roots.map { |root| File.join(root, rel) }.find { |p| File.file?(p) }
|
|
48
|
+
return unless path
|
|
49
|
+
|
|
50
|
+
FastImage.size(path)
|
|
51
|
+
rescue FastImage::ImageFetchError, FastImage::UnknownImageType
|
|
52
|
+
nil
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
data/lib/jekyll-imgflow.rb
CHANGED
|
@@ -24,6 +24,7 @@ require_relative "jekyll-imgflow/build_time_processor"
|
|
|
24
24
|
require_relative "jekyll-imgflow/parser"
|
|
25
25
|
require_relative "jekyll-imgflow/tags/tag_registry"
|
|
26
26
|
require_relative "jekyll-imgflow/modal_assets"
|
|
27
|
+
require_relative "jekyll-imgflow/intrinsic_dimensions"
|
|
27
28
|
require_relative "jekyll-imgflow/html_generator"
|
|
28
29
|
require_relative "jekyll-imgflow/imgflow_tag"
|
|
29
30
|
require_relative "jekyll-imgflow/picture_tag_adaptor"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jekyll-imgflow
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Svend Gundestrup
|
|
@@ -75,6 +75,7 @@ files:
|
|
|
75
75
|
- lib/jekyll-imgflow/html_generator.rb
|
|
76
76
|
- lib/jekyll-imgflow/imgflow_tag.rb
|
|
77
77
|
- lib/jekyll-imgflow/interface.rb
|
|
78
|
+
- lib/jekyll-imgflow/intrinsic_dimensions.rb
|
|
78
79
|
- lib/jekyll-imgflow/manifest_manager.rb
|
|
79
80
|
- lib/jekyll-imgflow/modal_assets.rb
|
|
80
81
|
- lib/jekyll-imgflow/operation_processor.rb
|