hugo/resources
Bjørn Erik Pedersen 41a080b268 tocss: Add vars option
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-20 19:36:30 +01:00
..
images resources/images: Fix 2 animated GIF resize issues 2022-10-04 15:38:12 +02:00
internal all: gofmt -w -r 'interface{} -> any' . 2022-03-17 22:03:27 +01:00
jsconfig all: Format code with gofumpt 2020-12-03 13:12:58 +01:00
page Revise the fix for shortcode vs output format nilpointer 2022-10-26 13:00:21 +02:00
postpub all: gofmt -w -r 'interface{} -> any' . 2022-03-17 22:03:27 +01:00
resource Add resources.Copy 2022-05-25 10:35:31 +02:00
resource_factories resources: Increase timeout for http.Client 2022-12-03 15:47:47 +01:00
resource_transformers tocss: Add vars option 2022-12-20 19:36:30 +01:00
testdata deps: Upgrade github.com/bep/gowebp v0.1.0 => v0.2.0 2022-11-15 18:19:35 +01:00
errorResource.go resources/images: Add $image.Colors 2022-09-22 15:57:35 +02:00
image.go resources/images: Add $image.Colors 2022-09-22 15:57:35 +02:00
image_cache.go Fix MediaType when reading images from cache 2022-04-16 16:36:15 +02:00
image_extended_test.go all: gofmt -w -r 'interface{} -> any' . 2022-03-17 22:03:27 +01:00
image_test.go resources: Update golden image dithering exception list 2022-10-04 16:19:52 +02:00
integration_test.go resources: Improve error message on .Resize etc. on SVGs 2022-05-25 18:06:20 +02:00
post_publish.go Add basic "post resource publish support" 2020-04-07 21:59:20 +02:00
resource.go resources: Panic on Copy of Resource with .Err 2022-06-14 09:47:41 +02:00
resource_cache.go all: gofmt -w -r 'interface{} -> any' . 2022-03-17 22:03:27 +01:00
resource_cache_test.go Improve the server assets cache invalidation logic 2019-08-13 18:09:46 +02:00
resource_metadata.go Improve error messages, esp. when the server is running 2022-05-06 19:43:22 +02:00
resource_metadata_test.go all: gofmt -w -r 'interface{} -> any' . 2022-03-17 22:03:27 +01:00
resource_spec.go Also consider wrapped errors when checking for file IsNotExist errors 2022-12-14 13:51:06 +01:00
resource_test.go all: gofmt -w -r 'interface{} -> any' . 2022-03-17 22:03:27 +01:00
testhelpers_test.go Some godoc adjustments and image struct renames 2022-04-27 23:53:56 +02:00
transform.go resources/images: Add $image.Colors 2022-09-22 15:57:35 +02:00
transform_test.go Support PostProcess for all file types 2022-09-14 19:09:20 +02:00