mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
dartsass: Import CSS without extension at compile time
Applicable to Dart Sass only: - Sass imports with the .css extension indicate a plain CSS @import. - Sass imports without the .css extension are imported at compile time. Fixes #10592
This commit is contained in:
parent
271318ad78
commit
2662faf61f
2 changed files with 67 additions and 6 deletions
|
@ -109,6 +109,67 @@ T1: {{ $r.Content | safeHTML }}
|
||||||
/* foo */`)
|
/* foo */`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue 10592
|
||||||
|
func TestTransformImportMountedCSS(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
if !dartsass.Supports() {
|
||||||
|
t.Skip()
|
||||||
|
}
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- assets/main.scss --
|
||||||
|
@import "import-this-file.css";
|
||||||
|
@import "foo/import-this-mounted-file.css";
|
||||||
|
@import "compile-this-file";
|
||||||
|
@import "foo/compile-this-mounted-file";
|
||||||
|
a {color: main-scss;}
|
||||||
|
-- assets/_compile-this-file.css --
|
||||||
|
a {color: compile-this-file-css;}
|
||||||
|
-- assets/_import-this-file.css --
|
||||||
|
a {color: import-this-file-css;}
|
||||||
|
-- foo/_compile-this-mounted-file.css --
|
||||||
|
a {color: compile-this-mounted-file-css;}
|
||||||
|
-- foo/_import-this-mounted-file.css --
|
||||||
|
a {color: import-this-mounted-file-css;}
|
||||||
|
-- layouts/index.html --
|
||||||
|
{{- $opts := dict "transpiler" "dartsass" }}
|
||||||
|
{{- with resources.Get "main.scss" | toCSS $opts }}{{ .Content | safeHTML }}{{ end }}
|
||||||
|
-- config.toml --
|
||||||
|
disableKinds = ['RSS','sitemap','taxonomy','term','page','section']
|
||||||
|
|
||||||
|
[[module.mounts]]
|
||||||
|
source = 'assets'
|
||||||
|
target = 'assets'
|
||||||
|
|
||||||
|
[[module.mounts]]
|
||||||
|
source = 'foo'
|
||||||
|
target = 'assets/foo'
|
||||||
|
`
|
||||||
|
b := hugolib.NewIntegrationTestBuilder(
|
||||||
|
hugolib.IntegrationTestConfig{
|
||||||
|
T: t,
|
||||||
|
TxtarString: files,
|
||||||
|
NeedsOsFS: true,
|
||||||
|
},
|
||||||
|
).Build()
|
||||||
|
|
||||||
|
b.AssertFileContent("public/index.html", `
|
||||||
|
@import "import-this-file.css";
|
||||||
|
@import "foo/import-this-mounted-file.css";
|
||||||
|
a {
|
||||||
|
color: compile-this-file-css;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: compile-this-mounted-file-css;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: main-scss;
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
func TestTransformThemeOverrides(t *testing.T) {
|
func TestTransformThemeOverrides(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
if !dartsass.Supports() {
|
if !dartsass.Supports() {
|
||||||
|
|
|
@ -163,9 +163,9 @@ func (t importResolver) CanonicalizeURL(url string) (string, error) {
|
||||||
if strings.Contains(name, ".") {
|
if strings.Contains(name, ".") {
|
||||||
namePatterns = []string{"_%s", "%s"}
|
namePatterns = []string{"_%s", "%s"}
|
||||||
} else if strings.HasPrefix(name, "_") {
|
} else if strings.HasPrefix(name, "_") {
|
||||||
namePatterns = []string{"_%s.scss", "_%s.sass"}
|
namePatterns = []string{"_%s.scss", "_%s.sass", "_%s.css"}
|
||||||
} else {
|
} else {
|
||||||
namePatterns = []string{"_%s.scss", "%s.scss", "_%s.sass", "%s.sass"}
|
namePatterns = []string{"_%s.scss", "%s.scss", "_%s.sass", "%s.sass", "_%s.css", "%s.css"}
|
||||||
}
|
}
|
||||||
|
|
||||||
name = strings.TrimPrefix(name, "_")
|
name = strings.TrimPrefix(name, "_")
|
||||||
|
|
Loading…
Reference in a new issue