Skip to content

Commit

Permalink
libsass: Resolve directory paths to directory index files
Browse files Browse the repository at this point in the history
Closes #12851
  • Loading branch information
jmooring authored and bep committed Sep 16, 2024
1 parent 2bc2765 commit 5b442b3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@ Styles: {{ $r.RelPermalink }}
// Issue 12849
func TestDirectoryIndexes(t *testing.T) {
t.Parallel()
if !dartsass.Supports() {
t.Skip()
}

files := `
-- hugo.toml --
Expand Down
5 changes: 3 additions & 2 deletions resources/resource_transformers/tocss/dartsass/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ moo {
@import "another.css";
/* foo */
`)
}

Expand Down Expand Up @@ -262,7 +262,7 @@ body {
body {
background: url($image) no-repeat center/cover;
font-family: $font;
}
}
}
p {
Expand Down Expand Up @@ -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}")
}
6 changes: 5 additions & 1 deletion resources/resource_transformers/tocss/scss/tocss.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "_")
Expand Down

0 comments on commit 5b442b3

Please sign in to comment.