aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-06-08 16:17:12 +0200
committerBjørn Erik Pedersen <[email protected]>2023-06-12 13:47:38 +0200
commitc782ebd89c4e40f9c7ce363359efc64e8355ad17 (patch)
tree7e4b0768ed87b0aa15e416cfc9a4439e9487f256 /resources
parent73779707a2d5fefd4915f8ee2021f265d841dea2 (diff)
downloadhugo-c782ebd89c4e40f9c7ce363359efc64e8355ad17.tar.gz
hugo-c782ebd89c4e40f9c7ce363359efc64e8355ad17.zip
Fix indented SASS imports for Dart Sass
Fixes #11074
Diffstat (limited to 'resources')
-rw-r--r--resources/resource_transformers/tocss/dartsass/integration_test.go32
-rw-r--r--resources/resource_transformers/tocss/dartsass/transform.go17
2 files changed, 45 insertions, 4 deletions
diff --git a/resources/resource_transformers/tocss/dartsass/integration_test.go b/resources/resource_transformers/tocss/dartsass/integration_test.go
index aa71101a0..d76592336 100644
--- a/resources/resource_transformers/tocss/dartsass/integration_test.go
+++ b/resources/resource_transformers/tocss/dartsass/integration_test.go
@@ -109,6 +109,38 @@ T1: {{ $r.Content | safeHTML }}
/* foo */`)
}
+func TestTransformImportIndentedSASS(t *testing.T) {
+ t.Parallel()
+ if !dartsass.Supports() {
+ t.Skip()
+ }
+
+ files := `
+-- assets/scss/_moo.sass --
+#main
+ color: blue
+-- assets/scss/main.scss --
+@import "moo";
+
+/* foo */
+-- config.toml --
+-- layouts/index.html --
+{{ $r := resources.Get "scss/main.scss" | toCSS (dict "transpiler" "dartsass") }}
+T1: {{ $r.Content | safeHTML }}
+
+ `
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ NeedsOsFS: true,
+ },
+ ).Build()
+
+ b.AssertFileContent("public/index.html", "T1: #main {\n color: blue;\n}\n\n/* foo */")
+}
+
// Issue 10592
func TestTransformImportMountedCSS(t *testing.T) {
t.Parallel()
diff --git a/resources/resource_transformers/tocss/dartsass/transform.go b/resources/resource_transformers/tocss/dartsass/transform.go
index 61ea54437..95dfd5944 100644
--- a/resources/resource_transformers/tocss/dartsass/transform.go
+++ b/resources/resource_transformers/tocss/dartsass/transform.go
@@ -86,7 +86,7 @@ func (t *transform) Transform(ctx *resources.ResourceTransformationCtx) error {
baseDir: baseDir,
c: t.c,
- varsStylesheet: sass.CreateVarsStyleSheet(opts.Vars),
+ varsStylesheet: godartsass.Import{Content: sass.CreateVarsStyleSheet(opts.Vars)},
},
OutputStyle: godartsass.ParseOutputStyle(opts.OutputStyle),
EnableSourceMap: opts.EnableSourceMap,
@@ -132,7 +132,7 @@ type importResolver struct {
baseDir string
c *Client
- varsStylesheet string
+ varsStylesheet godartsass.Import
}
func (t importResolver) CanonicalizeURL(url string) (string, error) {
@@ -184,11 +184,20 @@ func (t importResolver) CanonicalizeURL(url string) (string, error) {
return "", nil
}
-func (t importResolver) Load(url string) (string, error) {
+func (t importResolver) Load(url string) (godartsass.Import, error) {
if url == sass.HugoVarsNamespace {
return t.varsStylesheet, nil
}
filename, _ := paths.UrlToFilename(url)
b, err := afero.ReadFile(hugofs.Os, filename)
- return string(b), err
+
+ sourceSyntax := godartsass.SourceSyntaxSCSS
+ if strings.HasSuffix(filename, ".sass") {
+ sourceSyntax = godartsass.SourceSyntaxSASS
+ } else if strings.HasSuffix(filename, ".css") {
+ sourceSyntax = godartsass.SourceSyntaxCSS
+ }
+
+ return godartsass.Import{Content: string(b), SourceSyntax: sourceSyntax}, err
+
}