From 2bc27657d8b75eabdeaf4df8b354efed8e079169 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Fri, 13 Sep 2024 15:54:23 -0700 Subject: [PATCH] dartsass: Resolve directory paths to directory index files Closes #12849 --- .../dartsass/dartsass_integration_test.go | 40 +++++++++++++++++++ .../tocss/dartsass/transform.go | 6 ++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go index 4d48b3b6a..7b2b03dc0 100644 --- a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go +++ b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go @@ -562,3 +562,43 @@ Styles: {{ $r.RelPermalink }} b.AssertFileContent("public/index.html", "Styles: /scss/main.css") } + +// Issue 12849 +func TestDirectoryIndexes(t *testing.T) { + t.Parallel() + + 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" "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;} +` + + 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/dartsass/transform.go b/resources/resource_transformers/tocss/dartsass/transform.go index 99a5c3f68..ddf28723b 100644 --- a/resources/resource_transformers/tocss/dartsass/transform.go +++ b/resources/resource_transformers/tocss/dartsass/transform.go @@ -165,7 +165,11 @@ func (t importResolver) CanonicalizeURL(url string) (string, error) { } else if strings.HasPrefix(name, "_") { namePatterns = []string{"_%s.scss", "_%s.sass", "_%s.css"} } else { - namePatterns = []string{"_%s.scss", "%s.scss", "_%s.sass", "%s.sass", "_%s.css", "%s.css"} + namePatterns = []string{ + "_%s.scss", "%s.scss", "%s/_index.scss", + "_%s.sass", "%s.sass", "%s/_index.sass", + "_%s.css", "%s.css", + } } name = strings.TrimPrefix(name, "_")