From 1f0e79022b0da03b9232e095f329516978f993e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 10 Dec 2024 12:53:16 +0100 Subject: [PATCH] Fix Sass imports of on the form index.{scss,sass} Fixes #13123 --- .../dartsass/dartsass_integration_test.go | 26 ++++++++++--------- .../tocss/dartsass/transform.go | 1 + .../tocss/scss/scss_integration_test.go | 26 ++++++++++--------- .../resource_transformers/tocss/scss/tocss.go | 1 + 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go index 5d1b89eaf08..293fdfbcf86 100644 --- a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go +++ b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go @@ -577,23 +577,25 @@ disableKinds = ['page','section','rss','sitemap','taxonomy','term'] [[module.mounts]] source = 'assets' target = 'assets' - -[[module.imports]] -path = "github.com/gohugoio/hugoTestModule2" - -[[module.imports.mounts]] +[[module.mounts]] source = "miscellaneous/sass" target = "assets/sass" --- go.mod -- -module hugo-github-issue-12849 -- layouts/index.html -- {{ $opts := dict "transpiler" "dartsass" "outputStyle" "compressed" }} {{ (resources.Get "sass/main.scss" | toCSS $opts).Content }} -- assets/sass/main.scss -- -@use "foo"; // directory with index file from OS file system -@use "bar"; // directory with index file from module mount --- assets/sass/foo/_index.scss -- -.foo {color: red;} +@use "foo1"; // directory with _index file from OS file system +@use "bar1"; // directory with _index file from module mount +@use "foo2"; // directory with index file from OS file system +@use "bar2"; // directory with index file from module mount +-- assets/sass/foo1/_index.scss -- +.foo1 {color: red;} +-- miscellaneous/sass/bar1/_index.scss -- +.bar1 {color: blue;} +-- assets/sass/foo2/index.scss -- +.foo2 {color: red;} +-- miscellaneous/sass/bar2/index.scss -- +.bar2 {color: blue;} ` b := hugolib.NewIntegrationTestBuilder( @@ -603,7 +605,7 @@ module hugo-github-issue-12849 TxtarString: files, }).Build() - b.AssertFileContent("public/index.html", ".foo{color:red}.bar{color:green}") + b.AssertFileContent("public/index.html", ".foo1{color:red}.bar1{color:blue}.foo2{color:red}.bar2{color:blue}") } func TestIgnoreDeprecationWarnings(t *testing.T) { diff --git a/resources/resource_transformers/tocss/dartsass/transform.go b/resources/resource_transformers/tocss/dartsass/transform.go index c5f97abff3e..0d7b570627d 100644 --- a/resources/resource_transformers/tocss/dartsass/transform.go +++ b/resources/resource_transformers/tocss/dartsass/transform.go @@ -170,6 +170,7 @@ func (t importResolver) CanonicalizeURL(url string) (string, error) { "_%s.sass", "%s.sass", "_%s.css", "%s.css", "%s/_index.scss", "%s/_index.sass", + "%s/index.scss", "%s/index.sass", } } diff --git a/resources/resource_transformers/tocss/scss/scss_integration_test.go b/resources/resource_transformers/tocss/scss/scss_integration_test.go index 10309ad20e2..0154a463412 100644 --- a/resources/resource_transformers/tocss/scss/scss_integration_test.go +++ b/resources/resource_transformers/tocss/scss/scss_integration_test.go @@ -432,23 +432,25 @@ disableKinds = ['page','section','rss','sitemap','taxonomy','term'] [[module.mounts]] source = 'assets' target = 'assets' - -[[module.imports]] -path = "github.com/gohugoio/hugoTestModule2" - -[[module.imports.mounts]] +[[module.mounts]] source = "miscellaneous/sass" target = "assets/sass" --- go.mod -- -module hugo-github-issue-12849 -- layouts/index.html -- {{ $opts := dict "transpiler" "libsass" "outputStyle" "compressed" }} {{ (resources.Get "sass/main.scss" | toCSS $opts).Content }} -- assets/sass/main.scss -- -@import "foo"; // directory with index file from OS file system -@import "bar"; // directory with index file from module mount --- assets/sass/foo/_index.scss -- -.foo {color: red;} +@import "foo1"; // directory with _index file from OS file system +@import "bar1"; // directory with _index file from module mount +@import "foo2"; // directory with index file from OS file system +@import "bar2"; // directory with index file from module mount +-- assets/sass/foo1/_index.scss -- +.foo1 {color: red;} +-- miscellaneous/sass/bar1/_index.scss -- +.bar1 {color: blue;} +-- assets/sass/foo2/index.scss -- +.foo2 {color: red;} +-- miscellaneous/sass/bar2/index.scss -- +.bar2 {color: blue;} ` b := hugolib.NewIntegrationTestBuilder( @@ -458,5 +460,5 @@ module hugo-github-issue-12849 TxtarString: files, }).Build() - b.AssertFileContent("public/index.html", ".foo{color:red}.bar{color:green}") + b.AssertFileContent("public/index.html", ".foo1{color:red}.bar1{color:blue}.foo2{color:red}.bar2{color:blue}") } diff --git a/resources/resource_transformers/tocss/scss/tocss.go b/resources/resource_transformers/tocss/scss/tocss.go index 4b9c51ce05f..89e95b2f8bd 100644 --- a/resources/resource_transformers/tocss/scss/tocss.go +++ b/resources/resource_transformers/tocss/scss/tocss.go @@ -109,6 +109,7 @@ func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx "_%s.scss", "%s.scss", "_%s.sass", "%s.sass", "%s/_index.scss", "%s/_index.sass", + "%s/index.scss", "%s/index.sass", } }