mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-23 21:53:09 +02:00
resource_transformers/tocss: Fixed hugo:vars casting
Variables passed via the hugo:vars function where passed as type string. This caused problems when using the variables in sass functions because these expect a specific type. Now we check if the passed variables have to be quoted and therefore are of type string or if they should not be quoted and let the type interpretation up to the sass compiler. Fixes #10632
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
6abd15e781
commit
a1a9c08b5f
@@ -38,7 +38,12 @@ func CreateVarsStyleSheet(vars map[string]string) string {
|
||||
// These variables can be a combination of Sass identifiers (e.g. sans-serif), which
|
||||
// should not be quoted, and URLs et, which should be quoted.
|
||||
// unquote() is knowing what to do with each.
|
||||
varsSlice = append(varsSlice, fmt.Sprintf("%s%s: unquote(%q);", prefix, k, v))
|
||||
// Use quoteVar() to check if the variables should be quoted or not.
|
||||
if quoteVar(v) {
|
||||
varsSlice = append(varsSlice, fmt.Sprintf("%s%s: unquote(%q);", prefix, k, v))
|
||||
} else {
|
||||
varsSlice = append(varsSlice, fmt.Sprintf("%s%s: %s;", prefix, k, v))
|
||||
}
|
||||
}
|
||||
sort.Strings(varsSlice)
|
||||
varsStylesheet = strings.Join(varsSlice, "\n")
|
||||
@@ -46,3 +51,19 @@ func CreateVarsStyleSheet(vars map[string]string) string {
|
||||
return varsStylesheet
|
||||
|
||||
}
|
||||
|
||||
func quoteVar(v string) bool {
|
||||
v = strings.Trim(v, "\"")
|
||||
for _, p := range cssValues.prefix {
|
||||
if strings.HasPrefix(v, p) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
for _, s := range cssValues.sufix {
|
||||
if strings.HasSuffix(v, s) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
Reference in New Issue
Block a user