From 5b442b3ccef28a5fcf2e14289f5005c303880393 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Sun, 15 Sep 2024 15:10:37 -0700 Subject: [PATCH] libsass: Resolve directory paths to directory index files Closes #12851 --- .../dartsass/dartsass_integration_test.go | 3 ++ .../tocss/dartsass/transform.go | 5 +- .../tocss/scss/scss_integration_test.go | 47 ++++++++++++++++++- .../resource_transformers/tocss/scss/tocss.go | 6 ++- 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go index 7b2b03dc0a9..2aac2c5fb54 100644 --- a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go +++ b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go @@ -566,6 +566,9 @@ Styles: {{ $r.RelPermalink }} // Issue 12849 func TestDirectoryIndexes(t *testing.T) { t.Parallel() + if !dartsass.Supports() { + t.Skip() + } files := ` -- hugo.toml -- diff --git a/resources/resource_transformers/tocss/dartsass/transform.go b/resources/resource_transformers/tocss/dartsass/transform.go index ddf28723bea..f0bd6634af5 100644 --- a/resources/resource_transformers/tocss/dartsass/transform.go +++ b/resources/resource_transformers/tocss/dartsass/transform.go @@ -166,9 +166,10 @@ func (t importResolver) CanonicalizeURL(url string) (string, error) { namePatterns = []string{"_%s.scss", "_%s.sass", "_%s.css"} } else { namePatterns = []string{ - "_%s.scss", "%s.scss", "%s/_index.scss", - "_%s.sass", "%s.sass", "%s/_index.sass", + "_%s.scss", "%s.scss", + "_%s.sass", "%s.sass", "_%s.css", "%s.css", + "%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 46946387202..bd140cc88cf 100644 --- a/resources/resource_transformers/tocss/scss/scss_integration_test.go +++ b/resources/resource_transformers/tocss/scss/scss_integration_test.go @@ -111,7 +111,7 @@ moo { @import "another.css"; /* foo */ - + `) } @@ -262,7 +262,7 @@ body { body { background: url($image) no-repeat center/cover; font-family: $font; - } + } } p { @@ -417,3 +417,46 @@ h3 { b.AssertFileContent("public/index.html", `b.46b2d77c7ffe37ee191678f72df991ecb1319f849957151654362f09b0ef467f.css`) } + +// Issue 12851 +func TestDirectoryIndexes(t *testing.T) { + t.Parallel() + if !scss.Supports() { + t.Skip() + } + + files := ` +-- hugo.toml -- +disableKinds = ['page','section','rss','sitemap','taxonomy','term'] + +[[module.mounts]] +source = 'assets' +target = 'assets' + +[[module.imports]] +path = "github.com/gohugoio/hugoTestModule2" + +[[module.imports.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;} +` + + b := hugolib.NewIntegrationTestBuilder( + hugolib.IntegrationTestConfig{ + T: t, + NeedsOsFS: true, + TxtarString: files, + }).Build() + + b.AssertFileContent("public/index.html", ".foo{color:red}.bar{color:green}") +} diff --git a/resources/resource_transformers/tocss/scss/tocss.go b/resources/resource_transformers/tocss/scss/tocss.go index 3a46e601691..36ef2a77db4 100644 --- a/resources/resource_transformers/tocss/scss/tocss.go +++ b/resources/resource_transformers/tocss/scss/tocss.go @@ -105,7 +105,11 @@ func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx } else if strings.HasPrefix(name, "_") { namePatterns = []string{"_%s.scss", "_%s.sass"} } else { - namePatterns = []string{"_%s.scss", "%s.scss", "_%s.sass", "%s.sass"} + namePatterns = []string{ + "_%s.scss", "%s.scss", + "_%s.sass", "%s.sass", + "%s/_index.scss", "%s/_index.sass", + } } name = strings.TrimPrefix(name, "_")