Skip to content

Commit 2bc2765

Browse files
jmooringbep
authored andcommitted
dartsass: Resolve directory paths to directory index files
Closes #12849
1 parent 28f621d commit 2bc2765

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,43 @@ Styles: {{ $r.RelPermalink }}
562562

563563
b.AssertFileContent("public/index.html", "Styles: /scss/main.css")
564564
}
565+
566+
// Issue 12849
567+
func TestDirectoryIndexes(t *testing.T) {
568+
t.Parallel()
569+
570+
files := `
571+
-- hugo.toml --
572+
disableKinds = ['page','section','rss','sitemap','taxonomy','term']
573+
574+
[[module.mounts]]
575+
source = 'assets'
576+
target = 'assets'
577+
578+
[[module.imports]]
579+
path = "github.com/gohugoio/hugoTestModule2"
580+
581+
[[module.imports.mounts]]
582+
source = "miscellaneous/sass"
583+
target = "assets/sass"
584+
-- go.mod --
585+
module hugo-github-issue-12849
586+
-- layouts/index.html --
587+
{{ $opts := dict "transpiler" "dartsass" "outputStyle" "compressed" }}
588+
{{ (resources.Get "sass/main.scss" | toCSS $opts).Content }}
589+
-- assets/sass/main.scss --
590+
@use "foo"; // directory with index file from OS file system
591+
@use "bar"; // directory with index file from module mount
592+
-- assets/sass/foo/_index.scss --
593+
.foo {color: red;}
594+
`
595+
596+
b := hugolib.NewIntegrationTestBuilder(
597+
hugolib.IntegrationTestConfig{
598+
T: t,
599+
NeedsOsFS: true,
600+
TxtarString: files,
601+
}).Build()
602+
603+
b.AssertFileContent("public/index.html", ".foo{color:red}.bar{color:green}")
604+
}

resources/resource_transformers/tocss/dartsass/transform.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ func (t importResolver) CanonicalizeURL(url string) (string, error) {
165165
} else if strings.HasPrefix(name, "_") {
166166
namePatterns = []string{"_%s.scss", "_%s.sass", "_%s.css"}
167167
} else {
168-
namePatterns = []string{"_%s.scss", "%s.scss", "_%s.sass", "%s.sass", "_%s.css", "%s.css"}
168+
namePatterns = []string{
169+
"_%s.scss", "%s.scss", "%s/_index.scss",
170+
"_%s.sass", "%s.sass", "%s/_index.sass",
171+
"_%s.css", "%s.css",
172+
}
169173
}
170174

171175
name = strings.TrimPrefix(name, "_")

0 commit comments

Comments
 (0)