]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
libsass: Resolve directory paths to directory index files
authorJoe Mooring <joe.mooring@veriphor.com>
Sun, 15 Sep 2024 22:10:37 +0000 (15:10 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 16 Sep 2024 07:34:14 +0000 (09:34 +0200)
Closes #12851

resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go
resources/resource_transformers/tocss/dartsass/transform.go
resources/resource_transformers/tocss/scss/scss_integration_test.go
resources/resource_transformers/tocss/scss/tocss.go

index 7b2b03dc0a9c64474fe75934792953b7c801c60b..2aac2c5fb54e082440686400c48bd4e60191d9bb 100644 (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 --
index ddf28723beabbf9710cc24a1998432960f6accf8..f0bd6634af58a5c36a5f9d804d06d2e6477a6cdf 100644 (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",
                }
        }
 
index 469463872028ec699cb8408b7fac9e9638d01225..bd140cc88cf9893d5513034530b37057530f3a85 100644 (file)
@@ -111,7 +111,7 @@ moo {
 
 @import "another.css";
 /* foo */
-        
+
 `)
 }
 
@@ -262,7 +262,7 @@ body {
        body {
                background: url($image) no-repeat center/cover;
                font-family: $font;
-         }       
+         }
 }
 
 p {
@@ -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}")
+}
index 3a46e60169113351d20a1568c6d0ac154ee6a09e..36ef2a77db4975ea49ceffbd853535efef339415 100644 (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, "_")