Commit Graph

58 Commits

Author SHA1 Message Date
Bjørn Erik Pedersen 781fabf4e4 all: Run go fix ./... 2026-06-07 21:20:40 +02:00
Bjørn Erik Pedersen e8fefc8388 images: Force cache invalidation for AVIF target
Fixes #14990
2026-06-05 16:18:23 +02:00
Bjørn Erik Pedersen 341f575d2d images: Make AVIF chroma subsampling content-aware via the hint
Encode photo/picture hints (and the default) as YUV420 instead of YUV444,
keeping 444 for text/icon/drawing. Lossless stays 444.

This roughly halves the encoder's peak memory (42 -> 27 MiB/MP) and the
output size, while 444 remains available for sharp-edged content. A
3000x3000 image now needs ~239 MiB to encode, down from ~381 MiB (which
sat right at the 384 MiB WASM cap).

Closes #14987

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 18:54:56 +02:00
Bjørn Erik Pedersen 248241b6e1 Cap AVIF lossy quality at 99
Before this commit, lossy compression with 100 quality meant lossless compression, leading to a big gap between 99 and 100.

This commit caps the lossy quality at 99, ensuring that lossy compression is always lossy.

Fixes #14981
2026-06-04 14:42:08 +02:00
Bjørn Erik Pedersen 4e17421ec2 images: Recover from memory alloc errors in WASM image processors
Fixes #14985
2026-06-04 11:01:49 +02:00
Bjørn Erik Pedersen 90d9f812b2 Add image processing support for AVIF
The encode/decode is implemented in a WebAssembly module built from a
small C wrapper around libavif. Bundled libraries (statically linked,
compiled with the WASI SDK):

* libavif v1.4.1 (container + codec glue)
* libaom v3.14.1 (AV1 encoder + decoder)
* dav1d 1.5.3 (AV1 decoder)
* libyuv (Chromium pin) for color conversion
* parson for JSON message passing across the wasm boundary

HDR handling on the encoder:

* SDR images are written as BT.709 / sRGB / BT.601 (8-bit).
* 10-bit and up are written as BT.2020 primaries with PQ (SMPTE
  ST 2084) transfer and BT.2020-NCL matrix coefficients, signalled
  via CICP.
* Adobe-style SDR+gainmap inputs (e.g. Lightroom HDR exports) are
  baked into a single true-HDR image in BT.2020/PQ at 10-bit, with
  the CLLI (Content Light Level Information) box carried through so
  HDR-capable clients can tone-map correctly.

Limitations:

* Animated input (animated WebP/GIF) is collapsed to its first frame
  when re-encoded as AVIF; animated AVIF output is not yet supported.

Fixes #7837
2026-05-26 12:13:53 +02:00
Alexandre Vaz 9e64953338 js: Return error for missing batch imports
A stale or removed resource used by js.Batch could panic while the esbuild import loader read its content during a rebuild. Return the read error through the loader so esbuild reports a normal build error and a later rebuild can recover when the file returns.

Closes #13737
2026-05-13 17:15:14 +02:00
Bjørn Erik Pedersen e51e761d9c css: Make css.Build's file-loader URLs absolute to web context root
When CSS imports assets via the file loader (fonts, images), the emitted
URLs were relative to the CSS output directory. That broke when the CSS
was inlined into HTML, since browsers then resolved the URLs against the
page rather than the CSS file.

Set esbuild's PublicPath to the CSS output directory joined with the
site base path so URLs work whether the CSS is published as a file or
inlined.

Fixes #14849
2026-05-10 19:08:08 +02:00
Bjørn Erik Pedersen 8b40a96b6e warpc: Move to parson.c in https://github.com/kgabis/parson
And be specific about which commit we use.

Hugo treat this as an upstream dependency, so we would appreciate that any bugs will be reported and fixed upstream.

See #14823
2026-04-29 13:51:42 +02:00
Bjørn Erik Pedersen 7622dd86ce css: Support nested hugo:vars/<name> imports
Allow CSS variables to be grouped under sub-paths and imported via
@import "hugo:vars/mobile" (or @use for Dart Sass), so callers can pass
nested dicts like:

    {{ dict "primary-color" "blue" "mobile" (dict "primary-color" "red") }}

Top-level "hugo:vars" now skips nested map entries instead of emitting
garbage for them.

Fixes #14705

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 19:42:50 +02:00
Bjørn Erik Pedersen 7574e35b40 Replace the concurrent map with an identical upstream version 2026-04-20 18:33:59 +02:00
Bjørn Erik Pedersen 481baa0896 all: Replace NewIntegrationTestBuilder with Test/TestE/TestRunning 2026-04-03 21:17:45 +02:00
Bjørn Erik Pedersen 5d09b5e32a tpl/css: Support @import "hugo:vars" for CSS custom properties in css.Build
Closes #14699

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 21:02:13 +02:00
Bjørn Erik Pedersen 623722bb07 tpl/css: Allow the user to override single loader entries
Fixes #14623

 Co-authored-by: Joe Mooring <joe.mooring@veriphor.com>
2026-03-14 15:17:21 +01:00
Bjørn Erik Pedersen e431f90bc6 tpl/css: Fix external source maps
Fixes #14620
2026-03-14 12:08:18 +01:00
Bjørn Erik Pedersen a7cbcf15f0 tpl/css: Make default loader resolution for CSS @import and url() always behave the same
Before this commit, we did dynamic loader resolution for CSS bundling for resources resolved by Hugo while any fallback to ESBuild would fall back to a (potentially) empty loaders config.

This revises the logic to always use a static list (see below) if `loaders` is not set. This should be easier do document and less confusing for the end user.

````
".png", ".jpg", ".jpeg", ".gif", ".svg", ".webp", ".avif",
".woff", ".woff2", ".ttf", ".eot", ".otf"
````

Fixes #14619
2026-03-13 20:24:32 +01:00
Joe Mooring 36cdb2c789 internal/js: Add default mainFields for CSS builds
Closes #14614
2026-03-13 08:33:17 +01:00
Bjørn Erik Pedersen 3e3b849cc7 Add css.Build
Fixes #14609
Fixes #14613
2026-03-12 13:32:40 +01:00
Bjørn Erik Pedersen e3108225bf all: Run go fix ./... 2026-03-07 18:30:42 +01:00
Bjørn Erik Pedersen c9b88e4d15 internal/warpc: Fix SIGSEGV in Close() when dispatcher fails to start
Only set started=true when Start() succeeds, so Close() doesn't
attempt to close a nil dispatcher.

Fixes #14536
2026-03-07 15:30:07 +01:00
Bjørn Erik Pedersen 7eafef2269 internal/warpc: Make webp C defaults match the Go defaults
To avoid confusion.
2026-01-27 18:31:45 +01:00
Bjørn Erik Pedersen 5f5b2f378f testing: Skip some slow tests when not running in CI
Fixes #14438
2026-01-27 15:38:49 +01:00
Bjørn Erik Pedersen e569dd59a0 Misc webp performance work
*- Dynamic pool sizing for WebP and Katex based on CPU count
- WebP decode: use RGB (3 bytes) for opaque images instead of RGBA (4 bytes)
- Add new imaging.config with new encoder method option; this is default 4 (what we had before), if have tested with value 2 for a 30% speedup on my MacBook, but that does sacrifice quality in some cases (quality/speed trade-off 0-6)
- Track hasAlpha in decode response to enable RGB optimization
- Scale image processing workers (1->2) on high-core machines
- Add WebP benchmark test

On my MacBook Pro M1 Pro, I now get these numbers compared to Hugo v0.152.0:

```
goos: darwin
goarch: arm64
pkg: github.com/gohugoio/hugo/internal/warpc
cpu: Apple M1 Pro
        │ cmp152.bench │         fix-webpbench.bench         │
        │    sec/op    │    sec/op     vs base               │
Webp-10   162.6m ± 32%   145.3m ± 21%  -10.60% (p=0.026 n=6)

        │ cmp152.bench │          fix-webpbench.bench          │
        │     B/op     │     B/op       vs base                │
Webp-10   41.69Mi ± 0%   123.79Mi ± 0%  +196.92% (p=0.002 n=6)

        │ cmp152.bench │         fix-webpbench.bench         │
        │  allocs/op   │  allocs/op    vs base               │
Webp-10    9.963k ± 3%   18.797k ± 2%  +88.67% (p=0.002 n=6)
```

For general image resize benchmarks compared to Hugo v0.152.0 (note that that's not the result of this branch):

```bash
goos: darwin
goarch: arm64
pkg: github.com/gohugoio/hugo/resources/images
cpu: Apple M1 Pro
               │ cmp152.bench │         fix-webpbench.bench         │
               │    sec/op    │    sec/op     vs base               │
ImageResize-10   84.12m ± ∞ ¹   40.70m ± ∞ ¹  -51.61% (p=0.029 n=4)
¹ need >= 6 samples for confidence interval at level 0.95

               │ cmp152.bench  │         fix-webpbench.bench         │
               │     B/op      │     B/op       vs base              │
ImageResize-10   32.37Mi ± ∞ ¹   29.25Mi ± ∞ ¹  -9.64% (p=0.029 n=4)
¹ need >= 6 samples for confidence interval at level 0.95

               │ cmp152.bench │        fix-webpbench.bench         │
               │  allocs/op   │  allocs/op    vs base              │
ImageResize-10   11.34k ± ∞ ¹   12.03k ± ∞ ¹  +6.07% (p=0.029 n=4)
¹ need >= 6 samples for confidence interval at level 0.95
```

Closes #14370
2026-01-21 10:44:22 +01:00
Shravani Totre 2c611091fd warpc: Fix typed nil return in Start
Fixes a panic in Close() when initialization fails by ensuring Start returns a nil interface instead of a typed nil.

See #14372
2026-01-18 14:54:31 +01:00
Bjørn Erik Pedersen 608ed09a0a Rename common/maps to common/hmaps (#14384)
Go's stdlid now has a maps package, which is very useful. We have been using imports on the form `xmaps "maps"`, but auto import tools doesn't handle this, which is annoying.

I have been thinking about this for some time, but have been holding back because of all the import changes. However, now is a good time to do this, with very little unmerged code.
2026-01-16 11:47:46 +01:00
Bjørn Erik Pedersen e9b9b36f46 Fix alpha/fuzzy border issue with new webp decoder for images with with transparent background
Fixes #14339
2026-01-02 17:06:10 +01:00
Bjørn Erik Pedersen c6ae33c61d images: Add compression option to image config and clean up some of the options handling
The original idea of setting quality to 0 for lossless WebP was didn't allow a setting that made sense for both JPEG and WebP.

Note that the above didn't really work at all, so this should not break anything.
2025-12-29 21:38:19 +01:00
Simon Heimlicher ea9675f6e7 images: Fix WebP quality and hint parameters being ignored
Fixes #14316
2025-12-29 16:47:43 +01:00
Bjørn Erik Pedersen a8c5d0d00d Fix "image: unknown format" error
Fixes #14295
2025-12-22 17:49:44 +01:00
Joe Mooring 5f46da6e2a internal/warpc: Increase WebP memory limit to 256 MiB
Closes #14282


---------

Co-authored-by: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
2025-12-20 12:16:36 +01:00
Bjørn Erik Pedersen 65a76664e3 Add full filename to image processing error messages if possible
Fixes #14278
2025-12-18 17:46:26 +01:00
Bjørn Erik Pedersen 1b4514e020 Encode and Decode using the libwebp library via WASM with animation support
Fixes #10030
Fixes #8500
Fixes #12843
Fixes #8879
Fixes #12842
2025-12-16 19:29:16 +01:00
Bjørn Erik Pedersen b9b304a126 testing: Port integration tests to new templates structure
As introduced in  v0.146.0. Keep some legecy test to preserve backwards compatibility.
2025-11-27 12:00:15 +01:00
Bjørn Erik Pedersen 555dfa207a Speedup and simplify page assembly for deeper content trees
This commit moves to a forked version go-radix (fork source has not had any updates in 3 years.), whith 2 notable changes:

* It's generic (using Go generics) and thus removes a lot of type conversions/assertions.
* It allows nodes to be replaced during walk, which allows to partition the tree for parallel processing without worrying about locking.

For this repo, this means:

* The assembly step now processes nested sections in parallel, which gives a speedup for deep content trees with a slight allocation penalty (see benchmarks below).
* Nodes that needs to be reinserted are inserted directly.
* Also, there are some drive-by fixes of some allocation issues, e.g. avoid wrapping mutexes in returned anonomous functions, a common source of hidden allocations.

```
                                                                                   │ master.bench │           perf-p3.bench            │
                                                                                   │    sec/op    │   sec/op     vs base               │
AssembleDeepSiteWithManySections/depth=1/sectionsPerLevel=1/pagesPerSection=50-10     6.958m ± 3%   7.015m ± 3%        ~ (p=0.589 n=6)
AssembleDeepSiteWithManySections/depth=1/sectionsPerLevel=6/pagesPerSection=100-10    14.25m ± 1%   14.56m ± 8%        ~ (p=0.394 n=6)
AssembleDeepSiteWithManySections/depth=1/sectionsPerLevel=6/pagesPerSection=500-10    48.07m ± 3%   49.23m ± 3%        ~ (p=0.394 n=6)
AssembleDeepSiteWithManySections/depth=2/sectionsPerLevel=6/pagesPerSection=100-10    66.66m ± 4%   66.47m ± 6%        ~ (p=0.485 n=6)
AssembleDeepSiteWithManySections/depth=4/sectionsPerLevel=2/pagesPerSection=100-10    59.57m ± 4%   50.73m ± 5%  -14.85% (p=0.002 n=6)
geomean                                                                               28.54m        27.92m        -2.18%

                                                                                   │ master.bench │           perf-p3.bench            │
                                                                                   │     B/op     │     B/op      vs base              │
AssembleDeepSiteWithManySections/depth=1/sectionsPerLevel=1/pagesPerSection=50-10    4.513Mi ± 0%   4.527Mi ± 0%  +0.33% (p=0.002 n=6)
AssembleDeepSiteWithManySections/depth=1/sectionsPerLevel=6/pagesPerSection=100-10   15.35Mi ± 0%   15.49Mi ± 0%  +0.94% (p=0.002 n=6)
AssembleDeepSiteWithManySections/depth=1/sectionsPerLevel=6/pagesPerSection=500-10   62.50Mi ± 0%   63.19Mi ± 0%  +1.10% (p=0.002 n=6)
AssembleDeepSiteWithManySections/depth=2/sectionsPerLevel=6/pagesPerSection=100-10   86.78Mi ± 0%   87.73Mi ± 0%  +1.09% (p=0.002 n=6)
AssembleDeepSiteWithManySections/depth=4/sectionsPerLevel=2/pagesPerSection=100-10   62.96Mi ± 0%   63.66Mi ± 0%  +1.12% (p=0.002 n=6)
geomean                                                                              29.84Mi        30.11Mi       +0.92%

                                                                                   │ master.bench │           perf-p3.bench           │
                                                                                   │  allocs/op   │  allocs/op   vs base              │
AssembleDeepSiteWithManySections/depth=1/sectionsPerLevel=1/pagesPerSection=50-10     60.44k ± 0%   60.97k ± 0%  +0.87% (p=0.002 n=6)
AssembleDeepSiteWithManySections/depth=1/sectionsPerLevel=6/pagesPerSection=100-10    205.8k ± 0%   211.4k ± 0%  +2.70% (p=0.002 n=6)
AssembleDeepSiteWithManySections/depth=1/sectionsPerLevel=6/pagesPerSection=500-10    831.1k ± 0%   858.3k ± 0%  +3.27% (p=0.002 n=6)
AssembleDeepSiteWithManySections/depth=2/sectionsPerLevel=6/pagesPerSection=100-10    1.157M ± 0%   1.197M ± 0%  +3.41% (p=0.002 n=6)
AssembleDeepSiteWithManySections/depth=4/sectionsPerLevel=2/pagesPerSection=100-10    839.9k ± 0%   867.8k ± 0%  +3.31% (p=0.002 n=6)
geomean                                                                               398.5k        409.3k       +2.71%
```
2025-11-25 11:37:05 +01:00
Bjørn Erik Pedersen 04650ce778 all: Run modernize -fix ./...
Closes #14107
2025-11-05 21:05:42 +01:00
Bjørn Erik Pedersen 264022a75a Add roles and versions as new dimensions (in addition to language)
See the main issue #13776 for details.

Fixes #519
Fixes #13680
Fixes #13663
Fixes #13776
Fixes #13855
Fixes #13648
Fixes #13996
Fixes #14001
Fixes #14031
Fixes #13818
Fixes #13196
2025-11-05 20:39:25 +01:00
Bjørn Erik Pedersen 6334948515 Handle KaTeX warnings (#13760)
Co-authored-by: Joe Mooring <joe.mooring@veriphor.com>

Fixes #13735
2025-05-30 20:57:54 +02:00
Joe Mooring 013c8cfb25 tpl/transform: Expose the KaTeX strict option
Closes #13729
2025-05-23 19:21:38 +02:00
Bjørn Erik Pedersen 83cfdd78ca Reimplement and simplify Hugo's template system
See #13541 for details.

Fixes #13545
Fixes #13515
Closes #7964
Closes #13365
Closes #12988
Closes #4891
2025-04-06 20:59:41 +02:00
Bjørn Erik Pedersen 521911a576 all: Run modernize -fix ./... 2025-02-26 11:44:25 +01:00
Joe Mooring 503dcf6252 internal/warpc: Enable KaTeX mhchem extension 2025-02-14 10:04:15 +01:00
Bjørn Erik Pedersen d25f7ec172 js/esbuild: Add drop option
Fixes #13362
2025-02-13 13:26:46 +01:00
Bjørn Erik Pedersen 020253904f js/esbuild: Don't try to resolve packages in /assets marked as external
Fixes #13183
2024-12-22 21:29:18 +01:00
Bjørn Erik Pedersen 5c80cb0d20 js/esbuild: Add missing es2024 target 2024-12-17 14:35:13 +01:00
Bjørn Erik Pedersen a5e5be234c Fix panic on server rebuilds when using both base templates and template.Defer
Fixes #12963
2024-12-16 18:03:04 +01:00
Bjørn Erik Pedersen 565c30eac9 js: Fix js.Batch for multihost setups
Note that this is an unreleased feature.

Fixes #13151
2024-12-16 11:52:18 +01:00
Bjørn Erik Pedersen 744b8566ec Fix a rebuild on resource rename case 2024-12-16 08:33:10 +01:00
Bjørn Erik Pedersen 7de5317aef js/esbuild: Add runners after scripts 2024-12-16 08:33:10 +01:00
Bjørn Erik Pedersen 4cbd4ef991 js/esbuild: Batch: Avoid nil Instances slice
Ranging over a nil slice in Go works great, but is a hassle onced passed to JS.
2024-12-16 08:33:10 +01:00
Bjørn Erik Pedersen a834bb9f7e js/esbuild: Build groups in order of their ID
We already do this for scripts e.g. inside a group.

This makes sure that group A's entry points gets added before B's, which can be an important property, see https://github.com/evanw/esbuild/issues/399#issuecomment-1458680887
2024-12-13 13:29:35 +01:00