summaryrefslogtreecommitdiffstats
path: root/resources
AgeCommit message (Collapse)Author
2023-02-21Add page fragments support to RelatedBjørn Erik Pedersen
The main topic of this commit is that you can now index fragments (content heading identifiers) when calling `.Related`. You can do this by: * Configure one or more indices with type `fragments` * The name of those index configurations maps to an (optional) front matter slice with fragment references. This allows you to link page<->fragment and page<->page. * This also will index all the fragments (heading identifiers) of the pages. It's also possible to use type `fragments` indices in shortcode, e.g.: ``` {{ $related := site.RegularPages.Related .Page }} ``` But, and this is important, you need to include the shortcode using the `{{<` delimiter. Not doing so will create infinite loops and timeouts. This commit also: * Adds two new methods to Page: Fragments (can also be used to build ToC) and HeadingsFiltered (this is only used in Related Content with index type `fragments` and `enableFilter` set to true. * Consolidates all `.Related*` methods into one, which takes either a `Page` or an options map as its only argument. * Add `context.Context` to all of the content related Page API. Turns out it wasn't strictly needed for this particular feature, but it will soon become usefil, e.g. in #9339. Closes #10711 Updates #9339 Updates #10725
2023-01-25Only invoke a given cached partial onceBjørn Erik Pedersen
Note that this is backed by a LRU cache (which we soon shall see more usage of), so if you're a heavy user of cached partials it may be evicted and refreshed if needed. But in most cases every partial is only invoked once. This commit also adds a timeout (the global `timeout` config option) to make infinite recursion in partials easier to reason about. ``` name old time/op new time/op delta IncludeCached-10 8.92ms ± 0% 8.48ms ± 1% -4.87% (p=0.016 n=4+5) name old alloc/op new alloc/op delta IncludeCached-10 6.65MB ± 0% 5.17MB ± 0% -22.32% (p=0.002 n=6+6) name old allocs/op new allocs/op delta IncludeCached-10 117k ± 0% 71k ± 0% -39.44% (p=0.002 n=6+6) ``` Closes #4086 Updates #9588
2023-01-17Fix permalinks issue with repeated sectionsBjørn Erik Pedersen
Fixes #10377
2023-01-16Add fill HTTP Response info into .Data in resources.GetRemoteBjørn Erik Pedersen
See #10604
2023-01-16Fix HEAD method in resources.GetRemoteBjørn Erik Pedersen
Fixes #10604
2023-01-16Fix order when reading custom headers in resources.GetRemoteBjørn Erik Pedersen
Fixes #10616
2023-01-16deps: Upgrade github.com/evanw/esbuild v0.15.18 => v0.17.0Bjørn Erik Pedersen
Also add a test to make sure legal comments are preserved in JS bundles. Closes #10536
2023-01-07resource: Fix Go Doc vs .Data.IntegrityBjørn Erik Pedersen
2023-01-04Misc doc, code refactoring to improve documentationBjørn Erik Pedersen
2022-12-23Adjust "you need the extended version" error messageBjørn Erik Pedersen
2022-12-23resource/page: Add Page.AncestorsSepts
Fixes #10567
2022-12-22Add HUGO_PUBLISHDIR to the Node environmentBjørn Erik Pedersen
So you can do `process.env.HUGO_PUBLISHDIR` in your `postcss.config.js` to figure out where Hugo publishes its files. Note that the value will always be an absolute file path and will point to a directory on disk even when running `hugo server` in memory mode. If you write to this folder from PostCSS when running the server, you could run the server with one of these flags: ``` hugo server --renderToDisk hugo server --renderStaticToDisk ``` Fixes #10554
2022-12-21tocss: Add some more test casesBjørn Erik Pedersen
See #10555
2022-12-21tocss: Fix unquote case with double quotesSepts
See #10555
2022-12-20tocss: Add vars optionBjørn Erik Pedersen
This commit adds a new `vars` option to both the Sass transpilers (Dart Sass and Libsass). This means that you can pass a map with key/value pairs to the transpiler: ```handlebars {{ $vars := dict "$color1" "blue" "$color2" "green" "$font_size" "24px" }} {{ $cssOpts := (dict "transpiler" "dartsass" "outputStyle" "compressed" "vars" $vars ) }} {{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts }} ``` And the the variables will be available in the `hugo:vars` namespace. Example usage for Dart Sass: ```scss @use "hugo:vars" as v; p { color: v.$color1; font-size: v.$font_size; } ``` Note that Libsass does not support the `use` keyword, so you need to `import` them as global variables: ```scss @import "hugo:vars"; p { color: $color1; font-size: $font_size; } ``` Hugo will: * Add a missing leading `$` for the variable names if needed. * Wrap the values in `unquote('VALUE')` (Sass built-in) to get proper handling of identifiers vs other strings. This means that you can pull variables directly from e.g. the site config: ```toml [params] [params.sassvars] color1 = "blue" color2 = "green" font_size = "24px" image = "images/hero.jpg" ``` ```handlebars {{ $vars := site.Params.sassvars}} {{ $cssOpts := (dict "transpiler" "dartsass" "outputStyle" "compressed" "vars" $vars ) }} {{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts }} ``` Fixes #10555
2022-12-14Also consider wrapped errors when checking for file IsNotExist errorsBjørn Erik Pedersen
Fixes #10534
2022-12-13resources/js: Fix some import discrepancies between Hugo and ESBuildBjørn Erik Pedersen
This fixes the cases where ```js import 'imp2/index.js'; import 'imp3/foo.js'; ``` And these files lives in `assets` as: ``` imp2/index.ts imp3/foo.ts ``` Fixes #10527
2022-12-05dartsass: Add sourceMapIncludeSources optionBjørn Erik Pedersen
2022-12-03resources: Increase timeout for http.ClientAnton Sattarov
Increase timeout for http.Client in resources.GetRemote from 10 second to 1 minute Fixes #10478
2022-11-15deps: Upgrade github.com/bep/gowebp v0.1.0 => v0.2.0Bjørn Erik Pedersen
2022-10-26Revise the fix for shortcode vs output format nilpointerBjørn Erik Pedersen
We do lazy initialization and (potentially) reuse of an output format's rendered content. We do this evaluation when we start a new rendering a new output format. There are, however, situation where these borders gets crossed (e.g. accessing content from another output format). We have a check for this in place for most cases, but not the content rendering of inner markdown blocks inside shortcodes. This patch applies that same logic to the newly introduced RenderContent method (which is not available from the templates). Fixes #10391
2022-10-04resources: Update golden image dithering exception listBjørn Erik Pedersen
2022-10-04resources/images: Fix 2 animated GIF resize issuesBjørn Erik Pedersen
* Fix resize of animated GIF when target != GIF * Avoid processing all GIF frames if targetFormat != GIF Fixes #10354
2022-09-23Consolidate the glob case logicBjørn Erik Pedersen
Looking at the code as a whole, we ended up with a little to much "buttons". It turns out that doing case insensitive matching (lower both pattern and strings to match) performs just fine. Or at least, it gives the penalty to the people who uses mixed case filenames. ``` GetGlob/Default_cache-10 10.6ns ± 2% 10.6ns ± 1% ~ (p=0.657 n=4+4) GetGlob/Filenames_cache,_lowercase_searchs-10 10.6ns ± 2% 10.6ns ± 0% ~ (p=1.000 n=4+4) GetGlob/Filenames_cache,_mixed_case_searchs-10 29.7ns ± 1% 29.6ns ± 1% ~ (p=0.886 n=4+4) GetGlob/GetGlob-10 13.7ns ± 1% 13.7ns ± 0% ~ (p=0.429 n=4+4) name old alloc/op new alloc/op delta GetGlob/Default_cache-10 0.00B 0.00B ~ (all equal) GetGlob/Filenames_cache,_lowercase_searchs-10 0.00B 0.00B ~ (all equal) GetGlob/Filenames_cache,_mixed_case_searchs-10 5.00B ± 0% 5.00B ± 0% ~ (all equal) GetGlob/GetGlob-10 0.00B 0.00B ~ (all equal) name old allocs/op new allocs/op delta GetGlob/Default_cache-10 0.00 0.00 ~ (all equal) GetGlob/Filenames_cache,_lowercase_searchs-10 0.00 0.00 ~ (all equal) GetGlob/Filenames_cache,_mixed_case_searchs-10 1.00 ± 0% 1.00 ± 0% ~ (all equal) GetGlob/GetGlob-10 ```
2022-09-23hugofs: Fix glob case-sensitivity bugsatotake
On Linux, `hugofs.Glob` does not hit any directories which includes uppercase letters. (This does not happen on macOS.) Since `resources.GetMatch/Match` uses `Glob`, ``` {{ resources.GetMatch "Foo/bar.css" }} ``` this does not match `assets/Foo/bar.css` . On the other hand, you can get it with ``` {{ resources.Get "Foo/bar.css" }} ```
2022-09-22resources/images: Add $image.ColorsBjørn Erik Pedersen
Which returns the most dominant colors of an image using a simple histogram method. Fixes #10307
2022-09-14Support PostProcess for all file typesBjørn Erik Pedersen
Not just HTML. Fixes #10269
2022-09-06scss: Handle single-file sourcemaps correctlyJenny Rakoczy
Simple sites may only have one css file. Update the replace directive to correctly match single-file sourcemaps and multi-file sourcemaps. Verified locally with and without SASS and CSS imports. Fixes #8174
2022-06-14resources: Panic on Copy of Resource with .ErrBjørn Erik Pedersen
Fixes #10006
2022-06-13resources/page: Add :slugorfilename attributeDawid Potocki
Fixes #4739, #385
2022-06-12js: Resolve index.esm.jsBjørn Erik Pedersen
Same logic as for `index.{js,ts...}` files applies; if both `index.esm.js` and `index.js` exists (unlikely), you need to use the name with extension when importing, else the `index.js` will win. Fixes #8631
2022-06-12Add animated GIF supportBjørn Erik Pedersen
Note that this is for GIFs only (and not Webp). Fixes #5030
2022-06-12resources: Add a Gif source file to golden testsBjørn Erik Pedersen
2022-05-27Don't use the baseURL /path as part of the resource cache keyBjørn Erik Pedersen
As that prevents Hugo projects with sub paths in their `baseURL` to use themes with cached resources. Fixes #9787
2022-05-27postcss: Make the resource cache key more stableBjørn Erik Pedersen
By using the input map as the basis, which means the hash will not change if we add/rename/remove options. This happened in Hugo 0.99, as we added a new options. This is unortunate. Unfortunately this means that the cache keys for PostCSS will change one more time in 0.100, but will be stable going forward. Note that we have implemented this pattern in all the other resource transformers. Updates #9787
2022-05-27github: Set HUGO_BUILD_TAGS: extended when running testsBjørn Erik Pedersen
Also fix TestDecodeConfig/Basic which started to fail in the extended build in 0.99.1. Closes #9935
2022-05-25Fix error message when PostCSS config file is not foundBjørn Erik Pedersen
Fixes #9927
2022-05-25resources: Improve error message on .Resize etc. on SVGsBjørn Erik Pedersen
Fixes #9875
2022-05-25Add resources.CopyBjørn Erik Pedersen
Implemented by most Resource objects, but not Page (for now). Fixes #9313
2022-05-15Improve SASS errorsBjørn Erik Pedersen
Fixes #9897
2022-05-15postcss: Fix import error handlingBjørn Erik Pedersen
Note that we will now fail if `inlineImports` is enabled and we cannot resolve an import. You can work around this by either: * Use url imports or imports with media queries. * Set `skipInlineImportsNotFound=true` in the options Also get the argument order in the different NewFileError* funcs in line. Fixes #9895
2022-05-14errors: Misc improvementsBjørn Erik Pedersen
* Redo the server error template * Always add the content file context if relevant * Remove some now superflous error string matching * Move the server error template to _server/error.html * Add file context (with position) to codeblock render blocks * Improve JS build errors Fixes #9892 Fixes #9891 Fixes #9893
2022-05-14postcss: Fix line numbers in error messagesBjørn Erik Pedersen
Fixes #9880
2022-05-13js: Bump test dependencyBjørn Erik Pedersen
To work around a cache issue.
2022-05-08Add `clock` cli flagsatotake
Close #8787
2022-05-06Improve error messages, esp. when the server is runningBjørn Erik Pedersen
* Add file context to minifier errors when publishing * Misc fixes (see issues) * Allow custom server error template in layouts/server/error.html To get to this, this commit also cleans up and simplifies the code surrounding errors and files. This also removes the usage of `github.com/pkg/errors`, mostly because of https://github.com/pkg/errors/issues/223 -- but also because most of this is now built-in to Go. Fixes #9852 Fixes #9857 Fixes #9863
2022-04-27Some godoc adjustments and image struct renamesBjørn Erik Pedersen
2022-04-23Some godoc adjustmentsBjørn Erik Pedersen
2022-04-23resources/page: Mark some more interface methods as internalBjørn Erik Pedersen
For the new documenttion.
2022-04-23Deprecate page.Author and page.AuthorsBjørn Erik Pedersen
These are not documented, and they don't belong on Page. We should consider having author a first class citizen of Hugo, but as it is not it's better modelled as a taxonomy.