Add workaround for regular CSS imports in SCSS

Fixes #7059
This commit is contained in:
Bjørn Erik Pedersen
2020-03-16 17:49:47 +01:00
parent 03b93bb988
commit 1a8af7d4f0
4 changed files with 143 additions and 2 deletions

View File

@@ -14,6 +14,8 @@
package scss
import (
"regexp"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugolib/filesystems"
"github.com/gohugoio/hugo/resources"
@@ -72,3 +74,17 @@ func DecodeOptions(m map[string]interface{}) (opts Options, err error) {
return
}
var (
regularCSSImportTo = regexp.MustCompile(`.*(@import "(.*.css)";).*`)
regularCSSImportFrom = regexp.MustCompile(`.*(\/\* HUGO_IMPORT_START (.*) HUGO_IMPORT_END \*\/).*`)
)
func replaceRegularImportsIn(s string) (string, bool) {
replaced := regularCSSImportTo.ReplaceAllString(s, "/* HUGO_IMPORT_START $2 HUGO_IMPORT_END */")
return replaced, s != replaced
}
func replaceRegularImportsOut(s string) string {
return regularCSSImportFrom.ReplaceAllString(s, "@import \"$2\";")
}