diff options
Diffstat (limited to 'resources')
-rw-r--r-- | resources/resource_transformers/tocss/dartsass/transform.go | 4 | ||||
-rw-r--r-- | resources/resource_transformers/tocss/sass/helpers.go (renamed from resources/resource_transformers/tocss/internal/sass/helpers.go) | 21 | ||||
-rw-r--r-- | resources/resource_transformers/tocss/sass/helpers_test.go (renamed from resources/resource_transformers/tocss/internal/sass/helpers_test.go) | 0 | ||||
-rw-r--r-- | resources/resource_transformers/tocss/scss/tocss.go | 4 |
4 files changed, 22 insertions, 7 deletions
diff --git a/resources/resource_transformers/tocss/dartsass/transform.go b/resources/resource_transformers/tocss/dartsass/transform.go index f0bd6634a..d8b6ae5b4 100644 --- a/resources/resource_transformers/tocss/dartsass/transform.go +++ b/resources/resource_transformers/tocss/dartsass/transform.go @@ -29,7 +29,7 @@ import ( "github.com/gohugoio/hugo/resources" "github.com/gohugoio/hugo/resources/internal" - "github.com/gohugoio/hugo/resources/resource_transformers/tocss/internal/sass" + "github.com/gohugoio/hugo/resources/resource_transformers/tocss/sass" "github.com/spf13/afero" @@ -85,7 +85,7 @@ func (t *transform) Transform(ctx *resources.ResourceTransformationCtx) error { c: t.c, dependencyManager: ctx.DependencyManager, - varsStylesheet: godartsass.Import{Content: sass.CreateVarsStyleSheet(opts.Vars)}, + varsStylesheet: godartsass.Import{Content: sass.CreateVarsStyleSheet(sass.TranspilerDart, opts.Vars)}, }, OutputStyle: godartsass.ParseOutputStyle(opts.OutputStyle), EnableSourceMap: opts.EnableSourceMap, diff --git a/resources/resource_transformers/tocss/internal/sass/helpers.go b/resources/resource_transformers/tocss/sass/helpers.go index c1cef141e..d4091a39c 100644 --- a/resources/resource_transformers/tocss/internal/sass/helpers.go +++ b/resources/resource_transformers/tocss/sass/helpers.go @@ -24,9 +24,14 @@ import ( const ( HugoVarsNamespace = "hugo:vars" + // Transpiler implementation can be controlled from the client by + // setting the 'transpiler' option. + // Default is currently 'libsass', but that may change. + TranspilerDart = "dartsass" + TranspilerLibSass = "libsass" ) -func CreateVarsStyleSheet(vars map[string]any) string { +func CreateVarsStyleSheet(transpiler string, vars map[string]any) string { if vars == nil { return "" } @@ -49,12 +54,22 @@ func CreateVarsStyleSheet(vars map[string]any) string { varsSlice = append(varsSlice, fmt.Sprintf("%s%s: %v;", prefix, k, v)) } else { // unquote will preserve quotes around URLs etc. if needed. - varsSlice = append(varsSlice, fmt.Sprintf("%s%s: unquote(%q);", prefix, k, v)) + if transpiler == TranspilerDart { + varsSlice = append(varsSlice, fmt.Sprintf("%s%s: string.unquote(%q);", prefix, k, v)) + } else { + varsSlice = append(varsSlice, fmt.Sprintf("%s%s: unquote(%q);", prefix, k, v)) + } } } } sort.Strings(varsSlice) - varsStylesheet = strings.Join(varsSlice, "\n") + + if transpiler == TranspilerDart { + varsStylesheet = `@use "sass:string";` + "\n" + strings.Join(varsSlice, "\n") + } else { + varsStylesheet = strings.Join(varsSlice, "\n") + } + return varsStylesheet } diff --git a/resources/resource_transformers/tocss/internal/sass/helpers_test.go b/resources/resource_transformers/tocss/sass/helpers_test.go index ef31fdd8f..ef31fdd8f 100644 --- a/resources/resource_transformers/tocss/internal/sass/helpers_test.go +++ b/resources/resource_transformers/tocss/sass/helpers_test.go diff --git a/resources/resource_transformers/tocss/scss/tocss.go b/resources/resource_transformers/tocss/scss/tocss.go index 36ef2a77d..4b9c51ce0 100644 --- a/resources/resource_transformers/tocss/scss/tocss.go +++ b/resources/resource_transformers/tocss/scss/tocss.go @@ -31,7 +31,7 @@ import ( "github.com/gohugoio/hugo/identity" "github.com/gohugoio/hugo/media" "github.com/gohugoio/hugo/resources" - "github.com/gohugoio/hugo/resources/resource_transformers/tocss/internal/sass" + "github.com/gohugoio/hugo/resources/resource_transformers/tocss/sass" ) // Used in tests. This feature requires Hugo to be built with the extended tag. @@ -64,7 +64,7 @@ func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx } } - varsStylesheet := sass.CreateVarsStyleSheet(options.from.Vars) + varsStylesheet := sass.CreateVarsStyleSheet(sass.TranspilerLibSass, options.from.Vars) // To allow for overrides of SCSS files anywhere in the project/theme hierarchy, we need // to help libsass revolve the filename by looking in the composite filesystem first. |