hugo/resources/resource_transformers
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
..
babel Improve error messages, esp. when the server is running 2022-05-06 19:43:22 +02:00
htesting Rework the Destination filesystem to make --renderStaticToDisk work 2022-04-08 13:26:17 +02:00
integrity Improve error messages, esp. when the server is running 2022-05-06 19:43:22 +02:00
js resources/js: Fix some import discrepancies between Hugo and ESBuild 2022-12-13 18:58:17 +01:00
minifier minifiers: Make keepWhitespace = false default for HTML (note) 2022-03-09 07:48:18 +01:00
postcss Don't use the baseURL /path as part of the resource cache key 2022-05-27 19:11:16 +02:00
templates Improve error messages, esp. when the server is running 2022-05-06 19:43:22 +02:00
tocss tocss: Add vars option 2022-12-20 19:36:30 +01:00