Commit Graph

599 Commits

Author SHA1 Message Date
Bjørn Erik Pedersen ae7bf74b3e common/hexec: Make NODE_PATH a fallback for ESM bare imports
Node's ESM resolver does not consult NODE_PATH (unlike CJS require), so
an ESM postcss.config.js shipped by a Hugo theme fails when loaded from
the module cache: bare imports like `import x from "postcss-import"`
have no node_modules to walk up to.

Install a synchronous resolver hook (module.registerHooks) via
--import=data:... on every Node invocation. On ERR_MODULE_NOT_FOUND for
a bare specifier it resolves the package from each NODE_PATH entry via
createRequire().resolve(). No-op for relative, absolute, URL-scheme and
non-MODULE_NOT_FOUND failures. Synchronous hooks run on the main thread,
so no --allow-worker is needed under the Node permission model.

Fixes #13987

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 22:00:04 +02:00
Alexandre Vaz f0cfc28c00 resources/images: Keep smart crop target size
Smartcrop can return a crop rectangle that is smaller than the requested dimensions after prescaling and rounding. Expand that rectangle within the source image bounds before applying Hugo's crop/fill pipeline, so smart crops keep the requested size without stretching the image.

Bump the smart crop cache version for crop/fill only.

Fixes #13688

Co-Authored-By: Joe Mooring <joe.mooring@veriphor.com>
2026-05-13 12:10:44 +02:00
Bjørn Erik Pedersen 86fbb0f7a8 security: Validate redirects against security.http.urls
A server allowed by security.http.urls could redirect resources.GetRemote
to a host that is not. Re-run the check on each hop via CheckRedirect.

Fixes #14871
2026-05-13 10:06:43 +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 c4eba92863 resources: Honor Retry-After header in resources.GetRemote retries
When the server returns a temporary HTTP error (e.g. 429 or 503)
together with a Retry-After header, use that value as the next sleep
duration instead of the default exponential backoff. The Retry-After
value is also surfaced in the retry-timeout error message.

Fixes #14828
2026-04-29 15:44:16 +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 90d8bf34ae Replace deprecated .Site.Sites/.Page.Sites with hugo.Sites intests 2026-04-24 19:02:46 +02:00
Bjørn Erik Pedersen a54c398b93 Harden Node tool execution with --permission flag
Add security.node.permissions config to run Node tools (PostCSS, Babel,
TailwindCSS) under Node's permission model, restricting file system access
to the working directory by default.

The binary resolution is simplified to node_modules/.bin → PATH (npx removed).
For both locations, the actual JS entry point is resolved via symlinks (macOS/Linux)
or by parsing npm wrapper scripts (Windows .cmd), then executed as
"node --permission --allow-fs-read=<path> --allow-fs-write=<path> <script>".

Users can opt out by removing "node" from security.exec.allow.

Closes #7287
2026-04-22 15:47:34 +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 017a7cd63a Add slice-based permalinks config with PageMatcher target
Closes #14744
Clses #4641

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-19 19:45:45 +02:00
Joe Mooring 0d58e4286f resources/page: Add passing test for Issue #14325 2026-04-18 15:02:47 +02:00
Bjørn Erik Pedersen 9747724222 Fix it so we never auto-fallback to page resources in other roles/versions
This is some logic that's left behind from when we had only one dimension (language) where the common case would be to have one resource set (e.g. an image) and many content translation.

After this commit:

* For sites matrix defined in the content filename (e.g. data.en.js) or in its mount definition, we may use that as a fallback for e.g. German languages if we don't find a better match.
* For content adapters, this is not relevant: Here you must be explicit about this.
* We never auto-fallback on resources from a role/version to another.
* When a page bundle spans multiple roles (e.g. via roles = "*"), we clone its resources to all roles so each gets role-specific paths.

Fixes #14749
Fixes #14752
2026-04-14 16:33:38 +02:00
Bjørn Erik Pedersen 4e91e14cb0 Fix some recently introduced Position issues
Fixes #14710
2026-04-04 14:53:20 +02:00
Bjørn Erik Pedersen 481baa0896 all: Replace NewIntegrationTestBuilder with Test/TestE/TestRunning 2026-04-03 21:17:45 +02:00
Joe Mooring df520e3150 resources/page: Fix shared reader in Source.ValueAsOpenReadSeekCloser
Closes #14684

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 21:32:28 +01:00
Bjørn Erik Pedersen a8fca598e6 Replace deprecated site.Data with hugo.Data in tests
This also fixes a subtle server reload issue when changing files inside /data and using the recently added hugo.Data method.
2026-03-21 19:09:14 +01:00
Bjørn Erik Pedersen eb11c3d0bc Replace deprecated :filename with :contentbasename in the permalinks test 2026-03-18 08:47:26 +01:00
Bjørn Erik Pedersen 3c980c072e resources: Re-publish on transformation cache hit
When a resource transformation result was served from cache (same
options as a previous build), the output file was not re-written to
disk. This caused incorrect output when toggling transformation
options (e.g. minify) back to a previously seen value in server mode.

Fixes #14629
2026-03-15 18:32:41 +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 3e3b849cc7 Add css.Build
Fixes #14609
Fixes #14613
2026-03-12 13:32:40 +01:00
Bjørn Erik Pedersen 842d8f1052 resources: Fix context canceled on GetRemote with per-request timeout
The per-request timeout context was cancelled via defer in the getRes
closure, before io.ReadAll(res.Body) in the outer scope could read
the response body. Fix this by returning the cancel function from
getRes so each caller manages its own cancel lifecycle.

Fixes #14611

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:45:14 +01:00
Bjørn Erik Pedersen c47ec23342 resources: Use full path for Exif etc. decoding error/warning messages
Fixes #12693
2026-03-08 23:03:57 +01:00
Bjørn Erik Pedersen e3108225bf all: Run go fix ./... 2026-03-07 18:30:42 +01:00
Joe Mooring d4f2122dea refactor: Deprecate language configuration and template methods
Configuration:

- languageCode      -> locale (either in root or per-language)
- languageName      -> label
- languageDirection -> direction

Methods:

- .Language.LanguageCode      -> .Language.Locale
- .Language.LanguageName      -> .Language.Label
- .Language.LanguageDirection -> .Language.Direction
- .Site.LanguageCode          -> .Site.Language.Locale

Example configuration:

[languages.en]
  direction = 'ltr'
  label     = 'English'
  locale    = 'en-US'
  weight    = 1

Closes #14269

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-04 11:45:52 +01:00
Bjørn Erik Pedersen 991d2f9aba Replace Exif with Meta in tests 2026-03-04 11:38:28 +01:00
Joe Mooring e8577771c3 resources: Improve getImageOps error message
Closes #14571
2026-02-26 22:20:08 +01:00
Bjørn Erik Pedersen 44dc3847f4 resources/images: Add IsImageResourceWithMeta etc. tests for bmp and gif
Closes #14568
2026-02-26 16:49:11 +01:00
Bjørn Erik Pedersen 8e28668b09 docs: Regen and fix the imaging docshelper output
Fixes #14562
2026-02-25 10:43:58 +01:00
Bjørn Erik Pedersen 49bfb1070b Add AVIF, HEIF and HEIC partial support (only metadata for now)
* Add AVIF, HEIF and HEIC partial support

* Add them as media types.
* Support reading metadata (Width, Height, Exif, etc.) from these formats.
* Add a new template function IsImageResourceMeta to check if a resource supports image metadata operations, which will return true for AVIF, HEIF and HEIC resources even if they don't support full image operations yet.

Fixes #14549
2026-02-24 19:45:12 +01:00
Joe Mooring b7203bbb3a resources/images: Adjust WebP processing defaults
defaultWebpUseSharpYuv: true => false
defaultWebpMethod: 4 => 2
2026-02-24 10:02:48 +01:00
Paul van Brouwershaven 2d691c7e47 Add per-request timeout option to resources.GetRemote 2026-02-23 16:38:13 +01:00
Bjørn Erik Pedersen 86aa62524f hugolib: Move site.Data to hugo.Data, deprecate Site.AllPages/BuildDrafts/Languages
This moves Site.Data to the hugo namespace as hugo.Data, following the
same pattern used for hugo.Sites. Also deprecate Site.AllPages,
Site.BuildDrafts, and Site.Languages.

Closes #14521

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 14:34:47 +01:00
Bjørn Erik Pedersen 29b8e17d29 hugolib: Adjust hugo.Sites.Default
Fixes #14531
2026-02-17 19:10:47 +01:00
Bjørn Erik Pedersen 3c823408ee Move common/hugo/HugoInfo to resources/page
* This break the circular dependency between hugolib and resources/page, and allow HugoInfo to use the proper Page ans Site interfaces.
* It's a little misplaced, but it makes everything easier to maintain and test, so that's well worth it.
2026-02-17 19:10:47 +01:00
Joe Mooring ab62320d6b hugolib: Add hugo.Sites and .Site.IsDefault(), modify .Site.Sites
Changes:

- Add hugo.Sites to return all sites for all dimensions
- Modify .Site.Sites to return all sites for all dimensions
- Deprecate .Site.Sites in favor of hugo.Sites
- Add .Site.IsDefault() to report whether the current site is the
  default site across all dimensions
- Consolidate tests

Closes #14479
Closes #14481

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-16 18:57:26 +01:00
Joe Mooring 19ab3f581c all: Change site to project where appropriate
Closes #14504
2026-02-12 20:52:56 +01:00
Bjørn Erik Pedersen af5051e759 Remove items deprecated <= v0.136.0 (note)
Template functions:
- data.GetCSV / getCSV (use resources.GetRemote)
- data.GetJSON / getJSON (use resources.GetRemote)
- crypto.FNV32a (use hash.FNV32a)
- resources.Babel (use js.Babel)
- resources.PostCSS (use css.PostCSS)
- resources.ToCSS (use css.Sass)

Page methods:
- .Page.NextPage (use .Page.Next)
- .Page.PrevPage (use .Page.Prev)

Paginator:
- .Paginator.PageSize (use .Paginator.PagerSize)

Site methods:
- .Site.LastChange (use .Site.Lastmod)
- .Site.Author (use .Site.Params.Author)
- .Site.Authors (use .Site.Params.Authors)
- .Site.Social (use .Site.Params.Social)
- .Site.IsMultiLingual (use hugo.IsMultilingual)
- .Sites.First (use .Sites.Default)

Site config:
- paginate (use pagination.pagerSize)
- paginatePath (use pagination.path)

File caches:
- getjson cache
- getcsv cache
2026-02-12 19:33:58 +01:00
Bjørn Erik Pedersen b358a65c8b Upgrade to Go 1.26 2026-02-12 15:34:33 +01:00
Joe Mooring 828ee720cc resources/page: Deprecate cascade._target in favor of cascade.target
Closes #14341
2026-02-12 13:50:37 +01:00
Bjørn Erik Pedersen 6bd2bde9d3 resources/image: Add some image decode/encode debug logging
Fixes #14337
Closes #14460
2026-02-01 22:46:01 +01:00
Bjørn Erik Pedersen b5d43cdc17 Fix image DecodeConfig regression of WebP images from file cache
Fixes #14453
2026-01-29 22:53:13 +01:00
Bjørn Erik Pedersen d67925f5a1 Add ./check.sh script
Running `mage check` takes too long time for user (and agent) iterations. That will eventualy run on CI.

This is a faster version that:

* Checks gofmt.
* Runs go vet.
* Runs staticcheck.
* Runs unit tests without the race flag.

It assumes that Go is installed, but will check if staticcheck is available and install it if not with go install.

It takes an optional argument to specify packages to check, otherwise it checks all packages.

This commit also enable local runs of the image golden tests.
2026-01-29 14:24:54 +01:00
Joe Mooring b1e1eede50 resources/images: Fix WebP useSharpYuv being ignored
Closes #14449
2026-01-29 10:50:37 +01:00
Bjørn Erik Pedersen fd49df8f7a resources/images: Fix comment for Quality field in ImageConfig 2026-01-28 08:41:23 +01:00
Bjørn Erik Pedersen 5916b61be9 Remove disableDate and disableLatLong from MetaConfig
Since the meta config is new (and exif config is deprecated), remove
these options from MetaConfig. The fields filter controls which metadata
is extracted, including Date and GPS fields.

The existing exif config options are preserved for backward compatibility.

Closes #14437

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 21:47:32 +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
Simon Heimlicher 48566b6f37 resources: Fix race condition in test helper
The fetchResourceForSpec function was reusing a single ReadSeekCloser
across multiple goroutines, causing a race condition when
TestImageTransformConcurrent runs with imageProcWorkers > 1.

This was exposed by commit e569dd59a ("Misc webp performance work")
which increased imageProcWorkers from 1 to 2.

Fix by creating a new reader on each call to the open function.

Fixes race condition causing segfault on Apple Silicon.

Co-authored-by: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
2026-01-24 15:41:29 +01:00
Bjørn Erik Pedersen b441472b69 Add modulequeries file cache for module version queries
This adds a new file cache named 'modulequeries' with a 24h maxAge
that caches JSON responses from 'go mod download -json' when querying
module versions with constraints (e.g., version = "<v3.0.0").

On subsequent builds, if the cached JSON exists and the module
directory it references is non-empty, the cached result is used
directly, skipping the costly VCS interaction entirely.

Fixes #14417
2026-01-24 14:25:34 +01:00
Bjørn Erik Pedersen ee91c707ee Make Page.Aliases more useful in multidimensional setups (note)
There are 2 fundamental changes related to alias handling in this PR:

1. the `Page.Aliases`` method returns a ready-to-use list of aliases, not the raw input data. This means that it's prefixed with correct dimension values (e.g. language code) and output format paths, and ready to use in e.g. Netlify's _redirects file.
2. We only render aliases for output formats that is both defined as `IsHTML` and `Permalinkable`.

See #14402
2026-01-23 18:52:35 +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