dartsass: Resolve directory paths to directory index files

Closes #12849
This commit is contained in:
Joe Mooring 2024-09-13 15:54:23 -07:00 committed by Bjørn Erik Pedersen
parent 28f621d4a7
commit 2bc27657d8
2 changed files with 45 additions and 1 deletions

View file

@ -562,3 +562,43 @@ Styles: {{ $r.RelPermalink }}
b.AssertFileContent("public/index.html", "Styles: /scss/main.css") 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}")
}

View file

@ -165,7 +165,11 @@ func (t importResolver) CanonicalizeURL(url string) (string, error) {
} else if strings.HasPrefix(name, "_") { } else if strings.HasPrefix(name, "_") {
namePatterns = []string{"_%s.scss", "_%s.sass", "_%s.css"} namePatterns = []string{"_%s.scss", "_%s.sass", "_%s.css"}
} else { } 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, "_") name = strings.TrimPrefix(name, "_")