summaryrefslogtreecommitdiffstats
path: root/resources
AgeCommit message (Collapse)Author
2022-01-12Only create LazyContentProvider for the non-rendering SiteBjørn Erik Pedersen
Which saves a fair amound of allocations: ``` gobench --package ./hugolib --bench "SiteNew/Regular_D" --base master ``` Before: ``` name old time/op new time/op delta SiteNew/Regular_Deep_content_tree-10 40.7ms ± 3% 41.2ms ± 1% ~ (p=0.343 n=4+4) name old alloc/op new alloc/op delta SiteNew/Regular_Deep_content_tree-10 27.7MB ± 0% 28.8MB ± 0% +3.76% (p=0.029 n=4+4) name old allocs/op new allocs/op delta SiteNew/Regular_Deep_content_tree-10 304k ± 0% 329k ± 0% +8.07% (p=0.029 n=4+4) ``` After: ``` name old time/op new time/op delta SiteNew/Regular_Deep_content_tree-10 34.2ms ± 1% 34.7ms ± 1% ~ (p=0.114 n=4+4) name old alloc/op new alloc/op delta SiteNew/Regular_Deep_content_tree-10 27.7MB ± 0% 28.1MB ± 0% +1.38% (p=0.029 n=4+4) name old allocs/op new allocs/op delta SiteNew/Regular_Deep_content_tree-10 304k ± 0% 314k ± 0% +3.03% (p=0.029 n=4+4) ``` Updates #8919
2022-01-12Fix missing page data for alternative formatsPaul Gottschling
When a template calls the .Translations function and a Hugo environment is using multiple output formats, a template that calls methods like .Summary and .Len on each translation will unexpectedly show empty return values for these methods. This is because each pageOutput's ContentProvider is assigned to a page.NopPage in newPageOutput. When *HugoSites.render assigns pageContentOutputs to pageOutputs in *pageState.shiftToOutputFormat, it reuses pageContentOutputs from other pageOutputs, leaving some pageContentOutputs as NopPages. While this approach conserves resources, sometimes it means that a template will unexpectedly call a method on a pageContentOutput that is actually a NopPage. In the case of ContentProvider methods called on translations for alternative output formats, the methods were called on NopPages. This change introduces LazyContentProvider, which performs late initialization when one of its methods is called. This way, we can reuse content in "normal" cases but ensure that ContentProvider methods work as expected when a pageOutput is not assigned a pageContentOutput during the initial pre-render phase. Fixes #8919
2022-01-11Add hugo.DepsBjørn Erik Pedersen
Fixes #8949
2022-01-04Misc depreation updatesBjørn Erik Pedersen
* Deprecate .Page.Path when backed by a file * site.Permalinks * --ignoreVendor (use --ignoreVendorPaths) Closes #9348 Closes #9349
2022-01-04Make the deprecated Page/File methods (from Hugo 0.55) ERRORBjørn Erik Pedersen
Closes #9346
2022-01-04Fix surprise OutputFormat.Rel overwritingPaul Gottschling
In page.NewOutputFormat, we take an output.Format f and use it to create a page.OutputFormat. If the format is canonical, we assign the final OutputFormat's Rel to "canonical" rather than using f.Rel. However, this leads to unexpected behavior for custom output formats, where a user can define a "rel" for a format via the config file. For example, the standard for "humans.txt" files requires using rel="author" in HTML "link" elements. Meanwhile, humans.txt is usually the only format used for its content. As a result, for Hugo configurations that define a humans.txt custom output format, Hugo will render "link" elements to content in this format with rel="canonical," rather than "author" as required by the standard. This commit changes page.NewOutputFormat to check whether a given format is user defined and, if so, skips assigning Rel to "canonical," even if isCanonical is true. Fixes #8030
2021-12-22media: Also consider extension in FromContentBjørn Erik Pedersen
As used in `resources.GetRemote`. This will now reject image files with text and text files with images.
2021-12-17Always use content to resolve content type in resources.GetRemoteBjørn Erik Pedersen
This is a security hardening measure; don't trust the URL extension or any `Content-Type`/`Content-Disposition` header on its own, always look at the file content using Go's `http.DetectContentType`. This commit also adds ttf and otf media type definitions to Hugo. Fixes #9302 Fixes #9301
2021-12-17Add resources.GetRemoteBjørn Erik Pedersen
In Hugo 0.89 we added remote support to `resources.Get`. In hindsight that was not a great idea, as a poll from many Hugo users showed. See Issue #9285 for more details. After this commit `resources.Get` only supports local resource lookups. If you want to support both, you need to use a construct similar to: Also improve some option case handling. ``` {{ resource := "" }} {{ if (urls.Parse $url).IsAbs }} {{ $resource = resources.GetRemote $url }} {{ else }} {{ $resource = resources.Get $url }} {{ end }} ``` Fixes #9285 Fixes #9296
2021-12-16Add some basic security policies with sensible defaultsBjørn Erik Pedersen
This ommmit contains some security hardening measures for the Hugo build runtime. There are some rarely used features in Hugo that would be good to have disabled by default. One example would be the "external helpers". For `asciidoctor` and some others we use Go's `os/exec` package to start a new process. These are a predefined set of binary names, all loaded from `PATH` and with a predefined set of arguments. Still, if you don't use `asciidoctor` in your project, you might as well have it turned off. You can configure your own in the new `security` configuration section, but the defaults are configured to create a minimal amount of site breakage. And if that do happen, you will get clear instructions in the loa about what to do. The default configuration is listed below. Note that almost all of these options are regular expression _whitelists_ (a string or a slice); the value `none` will block all. ```toml [security] enableInlineShortcodes = false [security.exec] allow = ['^dart-sass-embedded$', '^go$', '^npx$', '^postcss$'] osEnv = ['(?i)^(PATH|PATHEXT|APPDATA|TMP|TEMP|TERM)$'] [security.funcs] getenv = ['^HUGO_'] [security.http] methods = ['(?i)GET|POST'] urls = ['.*'] ```
2021-12-13Improve handling of remote image/jpeg resources (#9278)Joe Mooring
Add jpe, jif, and jfif to image/jpeg extensions. For remote image/jpeg without extension, always use jpg extension. Closes #9275
2021-12-10Allow user to handle/ignore errors in resources.GetBjørn Erik Pedersen
In Hugo 0.90.0 we introduced remote support in `resources.Get`. But with remote resources comes with a higher chance of failing a build (network issues, remote server down etc.). Before this commit we always failed the build on any unexpected error. This commit allows the user to check for any error (and potentially fall back to a default local resource): ```htmlbars {{ $result := resources.Get "https://gohugo.io/img/hugo-logo.png" }} {{ with $result }} {{ if .Err }} {{/* log the error, insert a default image etc. *}} {{ else }} <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt=""> {{ end }} {{ end }} ``` Note that the default behaviour is still to fail the build, but we will delay that error until you start using the `Resource`. Fixes #9529
2021-12-10Make resource.Get return nil on 404 not foundBjørn Erik Pedersen
This is in line with the interface declaration and also how local lookups work. Fixes #9267
2021-12-09Update to Go 1.17.4 and remove timeout in resources.GetBjørn Erik Pedersen
Fixes #9265
2021-12-07Add custom font support to images.TextBjørn Erik Pedersen
Fixes #9253
2021-12-07images: Fix cache busting of image text filterBjørn Erik Pedersen
See #9238
2021-12-07images: Text filter that draws text with the given options (#9239)Paul van Brouwershaven
Fixes #9238
2021-12-02resources: Add timeout to the HTTP request in GetBjørn Erik Pedersen
Workaround for https://github.com/golang/go/issues/49366
2021-12-02Add a remote retry for resources.GetBjørn Erik Pedersen
2021-12-02Make resources.Get use a file cache for remote resourcesPaul van Brouwershaven
Closes #9228
2021-11-30resources: Adjust the remote Get cache so it does not get evicted on restartsBjørn Erik Pedersen
We fill improve this, soon.
2021-11-30Add remote support to resources.GetPaul van Brouwershaven
Closes #5255 Supports #9044
2021-10-30resources: Rename excepted filenames for image golden testdataAnthony Fok
As documented in commit 30eea3915b67f72611a3b2f4547146d4c6a96864, some filenames have changed due to cache busting of PNG and Webp images. This resolves recent TestImageOperationsGolden failure on arm64, ppc64le and s390x. See #6387 and #8729
2021-10-19resources: Always preserve the original transform errorBjørn Erik Pedersen
2021-10-10Allow multiple plugins in the PostCSS options mapJoe Mooring
Usage: {{ $options := dict "use" "autoprefixer postcss-color-alpha" }} {{ $style := resources.Get "main.css" | resources.PostCSS $options }} Fixes #9015
2021-09-22Pass minification errors to the userPaul Gottschling
Previously, *minifyTransformation.Transform suppressed the error returned by t.m.Minify. This meant that when minification returned an error, the error would not reach the user. Instead, minification would silently fail. For example, if a JavaScript file included a call to the Date constructor with: new Date(2020, 04, 02) The package that the minification library uses to parse JS files, github.com/tdewolff/parse would return an error, since "04" would be parsed as a legacy octal. However, the JS file would remain un-minified with no error. Fixing this is not as simple as replacing "_" with an "err" in *minifyTransformation.Transform, however (though this is necessary). If we only returned this error from Transform, then hugolib.TestResourceMinifyDisabled would fail. Instead of being a no-op, as TestResourceMinifyDisabled expects, using the "minify" template function with a "disableXML=true" config setting instead returns the error, "minifier does not exist for mimetype." The "minifier does not exist" error is returned because of the way minifiers.New works. If the user's config disables minification for a particular MIME type, minifiers.New does not add it to the resulting Client's *minify.M. However, this also means that when the "minify" template function is executed, a *resourceAdapter's transformations still add a minification. When it comes time to call the minify.Minifier for a specific MIME type via *M.MinifyMimetype, the github.com/tdewolff/minify library throws the "does not exist" error for the missing MIME type. The solution was to change minifiers.New so, instead of skipping a minifier for each disabled MIME type, it adds a NoOpMinifier, which simply copies the source to the destination without minification. This means that when the "minify" template function is used for a particular resource, and that resource's MIME type has minification disabled, minification is genuinely skipped, and does not result in an error. In order to add this, I've fixed a possibly unwanted interaction between minifiers.TestConfigureMinify and hugolib.TestResourceMinifyDisabled. The latter disables minification and expects minification to be a no-op. The former disables minification and expects it to result in an error. The only reason hugolib.TestResourceMinifyDisabled passes in the original code is that the "does not exist" error is suppressed. However, we shouldn't suppress minification errors, since they can leave users perplexed. I've changed the test assertion in minifiers.TestConfigureMinify to expect no errors and a no-op if minification is disabled for a particular MIME type. Fixes #8954
2021-09-19resources: Use default math/rand.Source for concurrency safetyEmmanuel T Odeke
The source from NewSource is documented not to be safe for concurrency, and instead use the eefault source which is documented as safe. Fixes #8981
2021-09-01js: Fix import order for ./foo when both ./foo.js and ./foo/index.js existsBjørn Erik Pedersen
This is in line with how both Node and ESBuild's native import resolver does it. The ambiguous situations above were discovered trying to build AlpineJS v3. Note that the above was never an issue if you used `./foo.js` and similar to import the component. Fixes #8945
2021-08-22Prevent minifier from removing quoutes around post-processed attributesBjørn Erik Pedersen
Fixes #8884
2021-07-29Go back to WARNING for Page deprecationsBjørn Erik Pedersen
Do that in the next release, let's reduce the noise, we have enough changes as it is.
2021-07-28Handle toml.LocalDate and toml.LocalDateTime in front matterBjørn Erik Pedersen
See #8801
2021-07-27Add timezone support for front matter dates without oneBjørn Erik Pedersen
Fixes #8810
2021-07-25Bump all long-living deprecations to ERRORsBjørn Erik Pedersen
2021-07-19minifiers: Make keepWhitespace = true default for HTMLBjørn Erik Pedersen
Fixes #8771
2021-07-15hugofs: Make FileMeta a structBjørn Erik Pedersen
This commit started out investigating a `concurrent map read write` issue, ending by replacing the map with a struct. This is easier to reason about, and it's more effective: ``` name old time/op new time/op delta SiteNew/Regular_Deep_content_tree-16 71.5ms ± 3% 69.4ms ± 5% ~ (p=0.200 n=4+4) name old alloc/op new alloc/op delta SiteNew/Regular_Deep_content_tree-16 29.7MB ± 0% 27.9MB ± 0% -5.82% (p=0.029 n=4+4) name old allocs/op new allocs/op delta SiteNew/Regular_Deep_content_tree-16 313k ± 0% 303k ± 0% -3.35% (p=0.029 n=4+4) ``` See #8749
2021-07-10Add config.cascadeBjørn Erik Pedersen
This commit adds support for using the `cascade` keyword in your configuration file(s), e.g. `config.toml`. Note that * Every feature of `cascade` is available, e.g. `_target` to target specific page sets. * Pages, e.g. the home page, can overwrite the cascade defined in config. Fixes #8741
2021-07-07resources: Regenerate image golden testdataBjørn Erik Pedersen
Keep this as a separate commit as this isn't because the files have changed. The filenames have changed due to cache busting of PNG and Webp images. See #8729
2021-07-07Fix transparency problem when converting 32-bit images to WebPBjørn Erik Pedersen
Fixes #8729
2021-07-05exif: Log warning for metadata decode errorBrandon Woodford
see #8519
2021-06-18Split out the puthe path/filepath functions into common/pathsBjørn Erik Pedersen
So they can be used from the config package without cyclic troubles. Updates #8654
2021-06-17resources/image: Fix fill with smartcrop sometimes returning 0 bytes imagesBjørn Erik Pedersen
Fixes #7955
2021-06-14Misc config loading fixesBjørn Erik Pedersen
The main motivation behind this is simplicity and correctnes, but the new small config library is also faster: ``` BenchmarkDefaultConfigProvider/Viper-16 252418 4546 ns/op 2720 B/op 30 allocs/op BenchmarkDefaultConfigProvider/Custom-16 450756 2651 ns/op 1008 B/op 6 allocs/op ``` Fixes #8633 Fixes #8618 Fixes #8630 Updates #8591 Closes #6680 Closes #5192
2021-06-08Upgrade Instagram shortcodeBjørn Erik Pedersen
Fixes #7879
2021-06-07tpl/fmt: Add erroridf template funcBjørn Erik Pedersen
Fixes #8613
2021-04-25resources/page: Fix permalinks pattern detection for some of the sections ↵Bjørn Erik Pedersen
variants See #8363
2021-04-15Add webp image encoding supportBjørn Erik Pedersen
Fixes #5924
2021-03-30Add slice syntax to sections permalinks configBjørn Erik Pedersen
Fixes #8363
2021-03-14media: Make Type comparableBjørn Erik Pedersen
So we can use it and output.Format as map key etc. This commit also fixes the media.Type implementation so it does not need to mutate itself to handle different suffixes for the same MIME type, e.g. jpg vs. jpeg. This means that there are no Suffix or FullSuffix on media.Type anymore. Fixes #8317 Fixes #8324
2021-03-14deps: Update to esbuild v0.9.0Bjørn Erik Pedersen
2021-03-13exif: Fix handling of utf8 runes in nullString()Cameron Moore