aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJoe Mooring <[email protected]>2024-09-15 15:10:37 -0700
committerBjørn Erik Pedersen <[email protected]>2024-09-16 09:34:14 +0200
commit5b442b3ccef28a5fcf2e14289f5005c303880393 (patch)
tree54ef29330a021f1b7cc2ea9c4ecc9e3ca842f8d0
parent2bc27657d8b75eabdeaf4df8b354efed8e079169 (diff)
downloadhugo-5b442b3ccef28a5fcf2e14289f5005c303880393.tar.gz
hugo-5b442b3ccef28a5fcf2e14289f5005c303880393.zip
libsass: Resolve directory paths to directory index files
Closes #12851
-rw-r--r--resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go3
-rw-r--r--resources/resource_transformers/tocss/dartsass/transform.go5
-rw-r--r--resources/resource_transformers/tocss/scss/scss_integration_test.go47
-rw-r--r--resources/resource_transformers/tocss/scss/tocss.go6
4 files changed, 56 insertions, 5 deletions
diff --git a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go
index 7b2b03dc0..2aac2c5fb 100644
--- a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go
+++ b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go
@@ -566,6 +566,9 @@ Styles: {{ $r.RelPermalink }}
// Issue 12849
func TestDirectoryIndexes(t *testing.T) {
t.Parallel()
+ if !dartsass.Supports() {
+ t.Skip()
+ }
files := `
-- hugo.toml --
diff --git a/resources/resource_transformers/tocss/dartsass/transform.go b/resources/resource_transformers/tocss/dartsass/transform.go
index ddf28723b..f0bd6634a 100644
--- a/resources/resource_transformers/tocss/dartsass/transform.go
+++ b/resources/resource_transformers/tocss/dartsass/transform.go
@@ -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",
}
}
diff --git a/resources/resource_transformers/tocss/scss/scss_integration_test.go b/resources/resource_transformers/tocss/scss/scss_integration_test.go
index 469463872..bd140cc88 100644
--- a/resources/resource_transformers/tocss/scss/scss_integration_test.go
+++ b/resources/resource_transformers/tocss/scss/scss_integration_test.go
@@ -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}")
+}
diff --git a/resources/resource_transformers/tocss/scss/tocss.go b/resources/resource_transformers/tocss/scss/tocss.go
index 3a46e6016..36ef2a77d 100644
--- a/resources/resource_transformers/tocss/scss/tocss.go
+++ b/resources/resource_transformers/tocss/scss/tocss.go
@@ -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, "_")