Skip to content

Commit

Permalink
dartsass: Resolve directory paths to directory index files
Browse files Browse the repository at this point in the history
Closes #12849
  • Loading branch information
jmooring authored and bep committed Sep 15, 2024
1 parent 28f621d commit 2bc2765
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
6 changes: 5 additions & 1 deletion resources/resource_transformers/tocss/dartsass/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "_")
Expand Down

0 comments on commit 2bc2765

Please sign in to comment.