abqari 1.3.2 → 1.3.3

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: b16f9c47efa3ac30792cfb3e7a27c6649250763cc62eb89a520005e435977390
4
- data.tar.gz: e8912f12801b05054989914aa015a2592ff83e2d0cd7f1194e3949a93d89a171
3
+ metadata.gz: 501b5298d079b3310e5b5b2ce4eabfffb0dc7ba647fe817c675f02dd2bc0dc70
4
+ data.tar.gz: 0dbca01fdec096906eea79e1190631d0a78c58ec8abe98f1b59d82b24f1f3aca
5
5
  SHA512:
6
- metadata.gz: 841112a252c318af617db6cb6247a9fd0df0e0988389239eaa46a78de3341a2aff2e9c1700e7b6a32f1f4897bafabfcb3f210febcec272fbc5233b20c8a2b254
7
- data.tar.gz: 5a64f7f56825344fbb93a24b826398d92dd27e6c978633e43dbbf241ca940c37d438b0105df989b3bb98cd30dbf721fcafcd5625413b430790af542c56d03acc
6
+ metadata.gz: 56fbb9bb740d2e6227caaa7dfcefaf2116b5aedbfef1e22d7e1ba5f165d3884faafdb7705f39f1b5f26749508a505b90212375638aa35cab766210f6f2afdf62
7
+ data.tar.gz: 1a9ed7984636e0f62270b389b26aeffe72359e21b23d36e618ca6f38da8bd472aa50cc3c28d84afd3634bba97cb202a47be2acfb25b9a208cabefcde9364db31
data/CHANGELOG.md CHANGED
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ _Nothing yet._
11
+
12
+ ## [1.3.3] — 2026-12-02
13
+
14
+ ### Changed
15
+
16
+ - **Long SEO titles and descriptions are now editorial advice, not build
17
+ warnings.** Fixed character counts were treated as validity limits although
18
+ search results truncate to available display width. Missing descriptions and
19
+ duplicate titles remain warnings; length checks decode HTML entities first.
20
+
21
+ ### Fixed
22
+
23
+ - **Responsive images could be reported as oversized despite smaller browser
24
+ renditions.** The audit read only the first character of each source srcset
25
+ and counted the original-format fallback instead. It now groups alternatives
26
+ by picture/img element and budgets the largest local responsive rendition,
27
+ without adding mutually exclusive encodings. Heavy fallback budgets remain
28
+ visible as information, and oversized individual assets still raise findings.
29
+
10
30
  ## [1.3.2] — 2026-11-20
11
31
 
12
32
  ### Changed
@@ -1189,7 +1209,8 @@ run a real working author / publisher site.
1189
1209
  commonmarker ≥ 2.4 ships precompiled 4.0 binaries, which is what
1190
1210
  the `~> 2.4` floor bought.
1191
1211
 
1192
- [Unreleased]: https://github.com/grantrayner/abqari/compare/v1.3.2...HEAD
1212
+ [Unreleased]: https://github.com/grantrayner/abqari/compare/v1.3.3...HEAD
1213
+ [1.3.3]: https://github.com/grantrayner/abqari/compare/v1.3.2...v1.3.3
1193
1214
  [1.3.2]: https://github.com/grantrayner/abqari/compare/v1.3.1...v1.3.2
1194
1215
  [1.3.1]: https://github.com/grantrayner/abqari/compare/v1.3.0...v1.3.1
1195
1216
  [1.3.0]: https://github.com/grantrayner/abqari/compare/v1.2.0...v1.3.0
data/README.md CHANGED
@@ -11,7 +11,7 @@ optional overrides), while the engine — layouts, themes, helpers, asset
11
11
  pipeline — lives in the dependency. Forking the engine is also
12
12
  supported for users who want to own all the code.
13
13
 
14
- > **Status:** v1.3.1 — see
14
+ > **Status:** v1.3.3 — see
15
15
  > [CHANGELOG.md](https://github.com/grantrayner/abqari/blob/main/CHANGELOG.md).
16
16
  > Distributed via RubyGems (`gem install abqari`) and as a Bundler
17
17
  > path/git source. The API follows [semver](https://semver.org/) from
@@ -176,7 +176,7 @@ Test that it worked:
176
176
  abqari version
177
177
  ```
178
178
 
179
- You should see a version number, e.g. `abqari 1.3.1`. If you get
179
+ You should see a version number, e.g. `abqari 1.3.3`. If you get
180
180
  `command not found`, see [Troubleshooting](#troubleshooting) below.
181
181
 
182
182
  ### Step 3 — Create your first site
@@ -472,7 +472,7 @@ end
472
472
  Or — pin to a git ref while tracking pre-release work:
473
473
 
474
474
  ```ruby
475
- gem 'abqari', git: 'https://github.com/grantrayner/abqari.git', tag: 'v1.3.1'
475
+ gem 'abqari', git: 'https://github.com/grantrayner/abqari.git', tag: 'v1.3.3'
476
476
  ```
477
477
 
478
478
  Install the libvips C library once (hard dep for the image pipeline):
@@ -1755,6 +1755,14 @@ Variants are fingerprinted by `<source-path>:<width>:<format>:<quality>:<source-
1755
1755
 
1756
1756
  `bin/audit` flags pages with heavy image payloads:
1757
1757
 
1758
+ Responsive images count as one choice per picture/img element. The page budget
1759
+ uses its largest local responsive rendition, falling back to `src` when no local
1760
+ responsive source exists. It includes below-fold images, so it is a conservative
1761
+ full-page budget, not a measured first-load transfer. Large original-format
1762
+ fallback budgets remain visible separately. Check browser-selected URLs at
1763
+ supported viewport sizes before changing source artwork.
1764
+
1765
+
1758
1766
  - Single image > 500 KB → warn (> 1 MB → error)
1759
1767
  - Total image weight on one page > 1 MB → warn (> 3 MB → error)
1760
1768
 
@@ -1816,6 +1824,13 @@ To weaken a hardening directive (`object-src`, `frame-ancestors`, `base-uri`, `d
1816
1824
 
1817
1825
  ## SEO and social sharing
1818
1826
 
1827
+ Audit title/description length findings are informational editorial prompts.
1828
+ [Google documents no fixed character limit](https://developers.google.com/search/docs/appearance/title-link)
1829
+ for titles, and [descriptions are truncated as needed](https://developers.google.com/search/docs/appearance/snippet).
1830
+ Keep text concise, accurate and useful; do not truncate it solely to meet a count.
1831
+ Missing descriptions and duplicate titles remain warnings.
1832
+
1833
+
1819
1834
  Solid SEO ships as standard — there is nothing to install and no
1820
1835
  plugin to configure. Once `environments.production.url` is set in
1821
1836
  `config/site.yml`, every page automatically gets:
@@ -2333,7 +2348,7 @@ Rebuilds the site, walks the output, and writes a markdown report to `audit/<YYY
2333
2348
  | Category | Checks |
2334
2349
  | --- | --- |
2335
2350
  | **Links** | Broken internal links and asset references |
2336
- | **SEO** | Title length (>60), description length (>160 or missing), duplicate titles |
2351
+ | **SEO** | Advisory title (>60) and description (>160) length; warnings for missing descriptions and duplicate titles |
2337
2352
  | **Accessibility** | Images without `alt`, multiple `<h1>` per page |
2338
2353
  | **Privacy** | External resource loads (URLs not on the site host) |
2339
2354
  | **Dependencies** | Outdated gems via `bundle outdated`, CVEs via `bundle-audit` (if installed) |
@@ -2573,7 +2588,7 @@ changes to your site. To track a fork or an unreleased branch
2573
2588
  instead, swap the line for a git source:
2574
2589
 
2575
2590
  ```ruby
2576
- gem 'abqari', git: 'https://github.com/grantrayner/abqari.git', tag: 'v1.3.1'
2591
+ gem 'abqari', git: 'https://github.com/grantrayner/abqari.git', tag: 'v1.3.3'
2577
2592
  ```
2578
2593
 
2579
2594
  The cadence: read [CHANGELOG.md](https://github.com/grantrayner/abqari/blob/main/CHANGELOG.md) before each upgrade,
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cgi'
4
+
3
5
  module Abqari
4
6
  class Audit
5
7
  # Performance rule. Flags pages whose total image payload would
@@ -7,10 +9,10 @@ module Abqari
7
9
  # scores on otherwise-clean static sites.
8
10
  #
9
11
  # Two thresholds, both per-page:
10
- # - Total image bytes on a page (the page's complete image
11
- # payload across all `<img>` and `<picture><source>` URLs
12
- # pointing at same-origin paths). Warn over 1 MB, error over
13
- # 3 MB.
12
+ # - Sum the largest local rendition per image element, selecting
13
+ # responsive sources when present and fallback src otherwise.
14
+ # Warn over 1 MB, error over 3 MB. This includes lazy images;
15
+ # it is an asset budget, not measured initial network transfer.
14
16
  # - Single-image bytes. A 5 MB hero in an otherwise-light page
15
17
  # defeats the whole pipeline. Warn at 500 KB, error at 1 MB.
16
18
  #
@@ -27,37 +29,64 @@ module Abqari
27
29
  next if html =~ /<meta\s+http-equiv=["']refresh/i
28
30
 
29
31
  url = page_url(file)
30
- image_paths = extract_image_urls(html)
31
- next if image_paths.empty?
32
+ groups = image_groups(html)
33
+ next if groups.empty?
32
34
 
33
- sizes = image_paths.filter_map { |path| size_for(path) }
35
+ fallbacks = local_images(html.scan(/<img\b[^>]*>/i).filter_map { |tag| attribute(tag, 'src') })
36
+ sizes = (groups.flatten + fallbacks).uniq.filter_map { |path| size_for(path) }
34
37
  flag_heavy_singles(url, sizes)
35
- flag_heavy_page_total(url, sizes)
38
+ # One rendition is fetched per picture. Use the largest available
39
+ # source as a conservative budget, not a sum of mutually exclusive
40
+ # formats or an optimistic smallest-thumbnail estimate.
41
+ total = groups.uniq.sum do |paths|
42
+ paths.filter_map { |path| size_for(path)&.last }.max || 0
43
+ end
44
+ flag_heavy_page_total(url, total)
45
+ fallback_total = fallbacks.sum { |path| size_for(path).last }
46
+ if fallback_total >= PAGE_TOTAL_WARN && fallback_total != total
47
+ add(category: 'perf', severity: 'info', location: url,
48
+ message: "Fallback image budget is #{format_kb(fallback_total)}; responsive sources are audited separately",
49
+ suggestion: 'Review legacy-browser support and compare actual image requests at supported viewport sizes.')
50
+ end
36
51
  end
37
52
  end
38
53
 
39
54
  private
40
55
 
41
- # Pull every `src="…"` and `srcset="…, …, …"` reference that
42
- # looks like a same-origin image path (`/...` or relative). We
43
- # only stat same-origin assets — external CDN images aren't
44
- # something the audit can size locally.
45
- def extract_image_urls(html)
46
- urls = []
47
-
48
- html.scan(/<img\s+[^>]*?src="([^"]+)"/i) { urls << ::Regexp.last_match(1) }
49
- html.scan(/<source\s+[^>]*?srcset="([^"]+)"/i) do |srcset,|
50
- srcset[0].to_s.split(',').each do |entry|
51
- url, = entry.strip.split(/\s+/, 2)
52
- urls << url if url
53
- end
56
+ # Scope alternatives to their element: identical basenames in different
57
+ # directories can be unrelated photos. Plain img srcset is responsive too.
58
+ def image_groups(html)
59
+ html.scan(%r{<picture\b[^>]*>.*?</picture>|<img\b[^>]*>}im).filter_map do |element|
60
+ sources = element.scan(/<source\b[^>]*>/i).flat_map { |tag| srcset_urls(tag) }
61
+ images = element.scan(/<img\b[^>]*>/i)
62
+ responsive = sources + images.flat_map { |tag| srcset_urls(tag) }
63
+ local = local_images(responsive)
64
+ # Do not claim a local byte budget for remote-only alternatives. The
65
+ # fallback is still useful when the picture has no local sources.
66
+ local = local_images(images.filter_map { |tag| attribute(tag, 'src') }) if local.empty?
67
+ local unless local.empty?
54
68
  end
69
+ end
55
70
 
56
- urls.uniq.reject { |u| u.empty? || u.start_with?('http://', 'https://', 'data:', '#') }
71
+ def attribute(tag, name)
72
+ match = tag.match(/(?:\A|\s)#{name}\s*=\s*(["'])(.*?)\1/im)
73
+ match && CGI.unescapeHTML(match[2])
74
+ end
75
+
76
+ def srcset_urls(tag)
77
+ value = attribute(tag, 'srcset')
78
+ return [] unless value
79
+
80
+ value.split(',').filter_map { |candidate| candidate.strip.split(/\s+/).first }
81
+ end
82
+
83
+ def local_images(urls)
84
+ urls.uniq.reject { |url| url.empty? || url.start_with?('http:', 'https:', '//', 'data:', '#') }
85
+ .select { |url| size_for(url) }
57
86
  end
58
87
 
59
88
  def size_for(url)
60
- path = File.join(@site.output_dir, url.sub(%r{\A/}, ''))
89
+ path = File.join(@site.output_dir, url.split(/[?#]/, 2).first.sub(%r{\A/}, ''))
61
90
  return nil unless File.exist?(path) && File.file?(path)
62
91
 
63
92
  [url, File.size(path)]
@@ -77,16 +106,7 @@ module Abqari
77
106
  end
78
107
  end
79
108
 
80
- def flag_heavy_page_total(page_url, sizes)
81
- # Sum the smallest variant per logical image — a `<picture>`
82
- # block typically lists multiple widths for the same image
83
- # under different filenames, but a visitor only fetches one
84
- # per breakpoint. Take the smallest per basename as a fair
85
- # proxy for "what the visitor actually downloads".
86
- per_basename = sizes.group_by { |url, _| basename_key(url) }
87
- effective = per_basename.values.map { |group| group.map { |_, b| b }.min || 0 }
88
- total = effective.sum
89
-
109
+ def flag_heavy_page_total(page_url, total)
90
110
  severity = if total >= PAGE_TOTAL_ERROR then 'error'
91
111
  elsif total >= PAGE_TOTAL_WARN then 'warn'
92
112
  end
@@ -94,18 +114,8 @@ module Abqari
94
114
 
95
115
  threshold = severity == 'error' ? '3 MB' : '1 MB'
96
116
  add(category: 'perf', severity: severity, location: page_url,
97
- message: "Total image weight on this page is #{format_kb(total)} (over #{threshold})",
98
- suggestion: 'Reduce hero/figure count, or compress further. Consider lazy-loading below-fold images via `loading="lazy"` (already default on auto-optimised images).')
99
- end
100
-
101
- def basename_key(url)
102
- # Strip the `-<width>.<hash>` fingerprint suffix so variants of
103
- # the same source coalesce: hero-1200.abc123.jpg → hero.jpg
104
- # and hero-800.def456.avif → hero.avif both bucket under their
105
- # base filename.
106
- bn = File.basename(url)
107
- ext = File.extname(bn)
108
- bn.sub(/-\d+\.[0-9a-f]+#{Regexp.escape(ext)}\z/, ext)
117
+ message: "Image rendition budget on this page is #{format_kb(total)} (over #{threshold})",
118
+ suggestion: 'Reduce image dimensions or compression size. This is a conservative full-page rendition budget; measure actual requests at supported viewport sizes too.')
109
119
  end
110
120
 
111
121
  def format_kb(bytes)
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cgi'
4
+
3
5
  module Abqari
4
6
  class Audit
5
7
  # SEO rule. Catches:
@@ -36,28 +38,32 @@ module Abqari
36
38
 
37
39
  private
38
40
 
41
+ # Length is an editorial review hint, not an SEO validity failure.
42
+ # Google documents no fixed limit for titles or meta descriptions.
39
43
  def check_title(html, url, titles)
40
44
  title = html[%r{<title>(.*?)</title>}m, 1]
41
45
  return unless title
42
46
 
47
+ title = CGI.unescapeHTML(title)
43
48
  (titles[title] ||= []) << url
44
49
  return unless title.length > TITLE_MAX_CHARS
45
50
 
46
- add(category: 'seo', severity: 'warn', location: url,
51
+ add(category: 'seo', severity: 'info', location: url,
47
52
  message: "Title is #{title.length} chars",
48
- suggestion: "Aim for #{TITLE_MAX_CHARS} or fewer for search snippets")
53
+ suggestion: 'Review for clarity and unnecessary branding. Search results truncate by display width; there is no fixed character limit.')
49
54
  end
50
55
 
51
56
  def check_description(html, url)
52
57
  desc = html[/<meta name="description" content="([^"]*)"/, 1]
53
58
 
59
+ desc = CGI.unescapeHTML(desc) if desc
54
60
  if desc.nil? || desc.empty?
55
61
  add(category: 'seo', severity: 'warn', location: url,
56
62
  message: 'Missing meta description')
57
63
  elsif desc.length > DESC_MAX_CHARS
58
- add(category: 'seo', severity: 'warn', location: url,
64
+ add(category: 'seo', severity: 'info', location: url,
59
65
  message: "Description is #{desc.length} chars",
60
- suggestion: "Aim for #{DESC_MAX_CHARS} or fewer")
66
+ suggestion: 'Keep the summary accurate and useful. Search snippets truncate as needed; do not mechanically shorten reporting to a character count.')
61
67
  end
62
68
  end
63
69
 
@@ -14,5 +14,5 @@
14
14
  #
15
15
  # Keep this file dependency-free.
16
16
  module Abqari
17
- VERSION = '1.3.2'
17
+ VERSION = '1.3.3'
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abqari
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant Rayner