mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
resources: Address Dart Sass deprecation of global built-in functions
See https://github.com/sass/dart-sass/releases/tag/1.80.0 Fixes #12961
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
72352f205a
commit
889308dd85
@@ -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,
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user