libsass: Resolve directory paths to directory index files

Closes #12851
This commit is contained in:
Joe Mooring 2024-09-15 15:10:37 -07:00 committed by Bjørn Erik Pedersen
parent 2bc27657d8
commit 5b442b3cce
4 changed files with 56 additions and 5 deletions

View file

@ -566,6 +566,9 @@ Styles: {{ $r.RelPermalink }}
// Issue 12849
func TestDirectoryIndexes(t *testing.T) {
t.Parallel()
if !dartsass.Supports() {
t.Skip()
}
files := `
-- hugo.toml --

View file

@ -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",
}
}

View file

@ -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}")
}

View file

@ -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, "_")