jekyll-auto-thumbnails 2.2.0 → 2.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba5ecfc504a10dfd094946e47dc0062ef2c200a4650aa35694b27e389ad1dc15
4
- data.tar.gz: 65e33707b09dbafeb8fbd5cc9d6f2dbced647e403e9ef78d84a0201466d39cb6
3
+ metadata.gz: 9e9c5ede1e1900fe3074040b44f1566cd3b697068f2e580d4a1087896692533c
4
+ data.tar.gz: 4514e267830f68e4b881fdf0bfffbcdd882e8211d199d6e702b4314750159d3f
5
5
  SHA512:
6
- metadata.gz: 2ddbcd68c77f775d8932b7e42f101b99d164a29bed79e4c176d5606e0afb7234277353483526aa67e1eb92ce5d3fcf2c5f0ca88d091f58b105b8f4f51eb5f7d5
7
- data.tar.gz: 4e98ebbe7ea692d0ca7b4b17e2b4c4136db49f026c8d7484ac3a18667503115e08735269df5e933912ad19d9ecddae81fb713c6dea1e9ea14a037360bb8907df
6
+ metadata.gz: 1313ca36c9f012d43a1e26b17308607293ac4a536f22f4186f3f8690934b30cdb3c5549db96ce27549c55062ba090744d770828ff62f235bb2ef804b20192b25
7
+ data.tar.gz: ad178e312f32bc8511a2a42dba2b5fbd31bd96e24acc8ffe2e37fb6ad3dbabba189aaca0efaaddcdd3b91726dcc17cfe95c6284d28854e9377cb91c72ab1afac
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.2.1](https://github.com/Texarkanine/jekyll-auto-thumbnails/compare/v2.2.0...v2.2.1) (2026-11-23)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **ci:** let the lockfile job commit inside the Ruby image ([#73](https://github.com/Texarkanine/jekyll-auto-thumbnails/issues/73)) ([7464ef4](https://github.com/Texarkanine/jekyll-auto-thumbnails/commit/7464ef4937ce231de4f1ffa8fad162291ef10212))
9
+ * **deps:** bump nokogiri ([bc4c2a2](https://github.com/Texarkanine/jekyll-auto-thumbnails/commit/bc4c2a2bff998762f33c72b4909f65bbacb51238))
10
+ * **deps:** bump nokogiri from 1.19.4 to 1.19.7 in the production-deps group ([#68](https://github.com/Texarkanine/jekyll-auto-thumbnails/issues/68)) ([bc4c2a2](https://github.com/Texarkanine/jekyll-auto-thumbnails/commit/bc4c2a2bff998762f33c72b4909f65bbacb51238))
11
+ * write width and height on measured article images ([#71](https://github.com/Texarkanine/jekyll-auto-thumbnails/issues/71)) ([27d29c0](https://github.com/Texarkanine/jekyll-auto-thumbnails/commit/27d29c07d893f90cf30f3ce2d09f6c3f2d22368b))
12
+
3
13
  ## [2.2.0](https://github.com/Texarkanine/jekyll-auto-thumbnails/compare/v2.1.0...v2.2.0) (2026-08-13)
4
14
 
5
15
 
data/README.md CHANGED
@@ -69,7 +69,7 @@ Pages that contain no replaceable `<article><img>` are no longer re-serialized a
69
69
  - Images with `width` or `height` attributes → uses those dimensions
70
70
  - Unsized images exceeding max config → thumbnails to max dimensions
71
71
  3. **Generation**: Creates thumbnails with MD5-based caching in `.jekyll-cache/`
72
- 4. **URL Replacement**: Updates `<img src>` to point to thumbnails
72
+ 4. **Rewrite**: Points `<img src>` at a thumbnail when one was made, and writes `width` and `height` for the file the browser will load. A measured image whose `src` does not change still gets both numbers.
73
73
  5. **File Copying**: Copies thumbnails to `_site/` after build
74
74
 
75
75
  ## Usage Examples
@@ -49,18 +49,21 @@ module JekyllAutoThumbnails
49
49
 
50
50
  started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
51
51
 
52
- # Scan all documents and pages
52
+ # Scan all documents and pages. Measurements are file pixels, not thumbnail requests.
53
+ measurements = {}
53
54
  (site.documents + site.pages).each do |doc|
54
55
  next unless doc.output
55
56
  next unless html_document?(doc)
56
57
 
57
- Scanner.scan_html(doc.output, registry, config, site.source)
58
+ measurements.merge!(Scanner.scan_html(doc.output, registry, config, site.source))
58
59
  end
59
60
 
60
61
  Jekyll.logger.info "AutoThumbnails:", "Found #{registry.entries.size} images to optimize"
61
62
 
62
- # Generate thumbnails
63
+ # Generate thumbnails. A served size is the thumbnail file when src changes,
64
+ # and the measured file when it does not.
63
65
  url_map = {}
66
+ served = {}
64
67
  registry.entries.each do |url, requirements|
65
68
  cached_path = generator.generate(url, requirements[:width], requirements[:height])
66
69
 
@@ -75,11 +78,19 @@ module JekyllAutoThumbnails
75
78
  "#{url_dir}/#{thumb_filename}"
76
79
  end
77
80
  url_map[url] = thumb_url
81
+ width, height = Scanner.image_dimensions(cached_path)
82
+ served[url] = { width: width, height: height } if width && height
78
83
  else
79
84
  Jekyll.logger.warn "AutoThumbnails:", "Failed to generate thumbnail for #{url}"
80
85
  end
81
86
  end
82
87
 
88
+ measurements.each do |url, dims|
89
+ next if url_map.key?(url)
90
+
91
+ served[url] = dims
92
+ end
93
+
83
94
  # Store url_map for post_write hook
84
95
  site.data["auto_thumbnails_url_map"] = url_map
85
96
 
@@ -88,7 +99,7 @@ module JekyllAutoThumbnails
88
99
  next unless doc.output
89
100
  next unless html_document?(doc)
90
101
 
91
- doc.output = replace_urls(doc.output, url_map, parser: config.parser)
102
+ doc.output = replace_urls(doc.output, url_map, parser: config.parser, sizes: served)
92
103
  end
93
104
 
94
105
  elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
@@ -127,8 +138,9 @@ module JekyllAutoThumbnails
127
138
 
128
139
  # Replace image URLs in HTML.
129
140
  #
130
- # Returns the input string unchanged (object identity) when no replacement
131
- # was actually made. This is both a perf win for pages with no matching
141
+ # Returns the input string unchanged (object identity) when no article image
142
+ # changes. A change is a new thumbnail `src`, or a `width` and `height`
143
+ # taken from `sizes`. This is both a perf win for pages with no matching
132
144
  # images and a correctness win: the HTML4 path otherwise round-trips every
133
145
  # page through libxml2's serializer, which injects a spurious
134
146
  # `<meta http-equiv="Content-Type">` on HTML5 sites.
@@ -136,9 +148,10 @@ module JekyllAutoThumbnails
136
148
  # @param html [String] HTML content
137
149
  # @param url_map [Hash] original URL => thumbnail URL
138
150
  # @param parser [Symbol] :html5 (default) or :html4
151
+ # @param sizes [Hash] original URL => {width:, height:} for the file the browser will load
139
152
  # @return [String] modified HTML (or the input itself, unchanged)
140
- def self.replace_urls(html, url_map, parser: :html5)
141
- return html if url_map.empty?
153
+ def self.replace_urls(html, url_map, parser: :html5, sizes: {})
154
+ return html if url_map.empty? && sizes.empty?
142
155
  return html unless html.match?(/<img/i)
143
156
 
144
157
  doc = HtmlParser.parse(html, parser)
@@ -146,11 +159,26 @@ module JekyllAutoThumbnails
146
159
  modified = false
147
160
  doc.css("article img").each do |img|
148
161
  src = img["src"]
149
- thumb_url = url_map[src]
150
- next unless thumb_url
162
+ next unless src
163
+
164
+ if (thumb_url = url_map[src]) && img["src"] != thumb_url
165
+ img["src"] = thumb_url
166
+ modified = true
167
+ end
168
+
169
+ size = sizes[src]
170
+ next unless size && size[:width] && size[:height]
151
171
 
152
- img["src"] = thumb_url
153
- modified = true
172
+ width = size[:width].to_s
173
+ height = size[:height].to_s
174
+ if img["width"] != width
175
+ img["width"] = width
176
+ modified = true
177
+ end
178
+ if img["height"] != height
179
+ img["height"] = height
180
+ modified = true
181
+ end
154
182
  end
155
183
 
156
184
  modified ? doc.to_html : html
@@ -14,7 +14,9 @@ module JekyllAutoThumbnails
14
14
  # @param registry [Registry] image registry
15
15
  # @param config [Configuration] configuration
16
16
  # @param site_source [String] Jekyll site source (optional, for unsized image checking)
17
+ # @return [Hash] url => {width:, height:} for each local article image whose file was read
17
18
  def self.scan_html(html, registry, config, site_source = nil)
19
+ measurements = {}
18
20
  doc = HtmlParser.parse(html, config.parser)
19
21
 
20
22
  # Only process images in <article> tags
@@ -29,17 +31,21 @@ module JekyllAutoThumbnails
29
31
 
30
32
  if width || height
31
33
  # Only identify for aspect-ratio fill when a dimension is missing
32
- width, height = calculate_dimensions(src, width, height, site_source) if site_source && (!width || !height)
34
+ if site_source && (!width || !height)
35
+ width, height = calculate_dimensions(src, width, height, site_source, measurements: measurements)
36
+ end
33
37
 
34
38
  # Skip if dimensions match original (no thumbnail needed)
35
- next if site_source && dimensions_match_original?(src, width, height, site_source)
39
+ next if site_source && dimensions_match_original?(src, width, height, site_source, measurements: measurements)
36
40
 
37
41
  registry.register(src, width, height)
38
42
  elsif site_source && (config.max_width || config.max_height)
39
43
  # Unsized but max config exists - check actual dimensions
40
- check_and_register_oversized(src, registry, config, site_source)
44
+ check_and_register_oversized(src, registry, config, site_source, measurements: measurements)
41
45
  end
42
46
  end
47
+
48
+ measurements
43
49
  end
44
50
 
45
51
  # Check if image exceeds max dimensions and register if so
@@ -48,13 +54,16 @@ module JekyllAutoThumbnails
48
54
  # @param registry [Registry] image registry
49
55
  # @param config [Configuration] configuration
50
56
  # @param site_source [String] site source directory
51
- def self.check_and_register_oversized(url, registry, config, site_source)
57
+ # @param measurements [Hash, nil] url => {width:, height:} of files read during this scan
58
+ def self.check_and_register_oversized(url, registry, config, site_source, measurements: nil)
52
59
  file_path = UrlResolver.to_filesystem_path(url, site_source)
53
60
  return unless file_path && File.exist?(file_path)
54
61
 
55
62
  actual_width, actual_height = image_dimensions(file_path)
56
63
  return unless actual_height
57
64
 
65
+ record_measurement(measurements, url, actual_width, actual_height)
66
+
58
67
  # Check if exceeds max dimensions
59
68
  exceeds_width = config.max_width && actual_width > config.max_width
60
69
  exceeds_height = config.max_height && actual_height > config.max_height
@@ -88,14 +97,17 @@ module JekyllAutoThumbnails
88
97
  # @param width [Integer, nil] specified width
89
98
  # @param height [Integer, nil] specified height
90
99
  # @param site_source [String] site source directory
100
+ # @param measurements [Hash, nil] url => {width:, height:} of files read during this scan
91
101
  # @return [Array<Integer, Integer>] [width, height] with calculated dimension
92
- def self.calculate_dimensions(url, width, height, site_source)
102
+ def self.calculate_dimensions(url, width, height, site_source, measurements: nil)
93
103
  file_path = UrlResolver.to_filesystem_path(url, site_source)
94
104
  return [width, height] unless file_path && File.exist?(file_path)
95
105
 
96
106
  actual_width, actual_height = image_dimensions(file_path)
97
107
  return [width, height] unless actual_height
98
108
 
109
+ record_measurement(measurements, url, actual_width, actual_height)
110
+
99
111
  # Calculate missing dimension preserving aspect ratio
100
112
  if width && !height
101
113
  # Width specified, calculate height
@@ -122,20 +134,40 @@ module JekyllAutoThumbnails
122
134
  Integer(numeric)
123
135
  end
124
136
 
125
- # Check if requested dimensions match original dimensions
137
+ # Check if requested dimensions match original dimensions.
138
+ # A pair already recorded for this URL is that file, so the match uses it.
126
139
  #
127
140
  # @param url [String] image URL
128
141
  # @param width [Integer] requested width
129
142
  # @param height [Integer] requested height
130
143
  # @param site_source [String] site source directory
144
+ # @param measurements [Hash, nil] url => {width:, height:} of files read during this scan
131
145
  # @return [Boolean] true if dimensions match original
132
- def self.dimensions_match_original?(url, width, height, site_source)
146
+ def self.dimensions_match_original?(url, width, height, site_source, measurements: nil)
147
+ if (known = measurements&.[](url))
148
+ return width == known[:width] && height == known[:height]
149
+ end
150
+
133
151
  file_path = UrlResolver.to_filesystem_path(url, site_source)
134
152
  return false unless file_path && File.exist?(file_path)
135
153
 
136
154
  actual_width, actual_height = image_dimensions(file_path)
155
+ record_measurement(measurements, url, actual_width, actual_height)
137
156
 
138
157
  width == actual_width && height == actual_height
139
158
  end
159
+
160
+ # Remember a file's pixels. Direct callers omit the hash, and a failed read has no pair.
161
+ #
162
+ # @param measurements [Hash, nil]
163
+ # @param url [String]
164
+ # @param width [Integer, nil]
165
+ # @param height [Integer, nil]
166
+ def self.record_measurement(measurements, url, width, height)
167
+ return unless measurements && width && height
168
+
169
+ measurements[url] = { width: width, height: height }
170
+ end
171
+ private_class_method :record_measurement
140
172
  end
141
173
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllAutoThumbnails
4
- VERSION = "2.2.0"
4
+ VERSION = "2.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-auto-thumbnails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Texarkanine