mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 00:32:07 -05:00
parent
9a1e6d15a3
commit
20af9a0781
4 changed files with 70 additions and 25 deletions
|
@ -39,11 +39,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// https://github.com/gohugoio/hugo/issues/6730
|
// https://github.com/gohugoio/hugo/issues/6730
|
||||||
func TestHugoModulesTargetInSubFolder(t *testing.T) {
|
func TestHugoModulesVariants(t *testing.T) {
|
||||||
if !isCI() {
|
if !isCI() {
|
||||||
// TODO(bep) investigate why this fails when running in LiteIDE (it works from the shell).
|
|
||||||
t.Skip("skip (relative) long running modules test when running locally")
|
t.Skip("skip (relative) long running modules test when running locally")
|
||||||
}
|
}
|
||||||
|
|
||||||
config := `
|
config := `
|
||||||
baseURL="https://example.org"
|
baseURL="https://example.org"
|
||||||
workingDir = %q
|
workingDir = %q
|
||||||
|
@ -51,19 +51,26 @@ workingDir = %q
|
||||||
[module]
|
[module]
|
||||||
[[module.imports]]
|
[[module.imports]]
|
||||||
path="github.com/gohugoio/hugoTestModule2"
|
path="github.com/gohugoio/hugoTestModule2"
|
||||||
[[module.imports.mounts]]
|
%s
|
||||||
source = "templates/hooks"
|
|
||||||
target = "layouts/_default/_markup"
|
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
|
createConfig := func(workingDir, moduleOpts string) string {
|
||||||
|
return fmt.Sprintf(config, workingDir, moduleOpts)
|
||||||
|
}
|
||||||
|
|
||||||
|
newTestBuilder := func(t testing.TB, moduleOpts string) (*sitesBuilder, func()) {
|
||||||
b := newTestSitesBuilder(t)
|
b := newTestSitesBuilder(t)
|
||||||
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-target-in-subfolder-test")
|
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-variants")
|
||||||
b.Assert(err, qt.IsNil)
|
b.Assert(err, qt.IsNil)
|
||||||
defer clean()
|
|
||||||
b.Fs = hugofs.NewDefault(viper.New())
|
b.Fs = hugofs.NewDefault(viper.New())
|
||||||
b.WithWorkingDir(workingDir).WithConfigFile("toml", fmt.Sprintf(config, workingDir))
|
b.WithWorkingDir(workingDir).WithConfigFile("toml", createConfig(workingDir, moduleOpts))
|
||||||
b.WithTemplates("_default/single.html", `{{ .Content }}`)
|
b.WithTemplates(
|
||||||
|
"index.html", `
|
||||||
|
Param from module: {{ site.Params.Hugo }}|
|
||||||
|
{{ $js := resources.Get "jslibs/alpinejs/alpine.js" }}
|
||||||
|
JS imported in module: {{ with $js }}{{ .RelPermalink }}{{ end }}|
|
||||||
|
`,
|
||||||
|
"_default/single.html", `{{ .Content }}`)
|
||||||
b.WithContent("p1.md", `---
|
b.WithContent("p1.md", `---
|
||||||
title: "Page"
|
title: "Page"
|
||||||
---
|
---
|
||||||
|
@ -82,14 +89,50 @@ github.com/gohugoio/hugoTestModule2 v0.0.0-20200131160637-9657d7697877 h1:WLM2bQ
|
||||||
github.com/gohugoio/hugoTestModule2 v0.0.0-20200131160637-9657d7697877/go.mod h1:CBFZS3khIAXKxReMwq0le8sEl/D8hcXmixlOHVv+Gd0=
|
github.com/gohugoio/hugoTestModule2 v0.0.0-20200131160637-9657d7697877/go.mod h1:CBFZS3khIAXKxReMwq0le8sEl/D8hcXmixlOHVv+Gd0=
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
return b, clean
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("Target in subfolder", func(t *testing.T) {
|
||||||
|
|
||||||
|
b, clean := newTestBuilder(t, "ignoreImports=true")
|
||||||
|
defer clean()
|
||||||
|
|
||||||
b.Build(BuildCfg{})
|
b.Build(BuildCfg{})
|
||||||
|
|
||||||
b.AssertFileContent("public/p1/index.html", `<p>Page|https://bep.is|Title: |Text: A link|END</p>`)
|
b.AssertFileContent("public/p1/index.html", `<p>Page|https://bep.is|Title: |Text: A link|END</p>`)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Ignore config", func(t *testing.T) {
|
||||||
|
|
||||||
|
b, clean := newTestBuilder(t, "ignoreConfig=true")
|
||||||
|
defer clean()
|
||||||
|
|
||||||
|
b.Build(BuildCfg{})
|
||||||
|
|
||||||
|
b.AssertFileContent("public/index.html", `
|
||||||
|
Param from module: |
|
||||||
|
JS imported in module: |
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Ignore imports", func(t *testing.T) {
|
||||||
|
|
||||||
|
b, clean := newTestBuilder(t, "ignoreImports=true")
|
||||||
|
defer clean()
|
||||||
|
|
||||||
|
b.Build(BuildCfg{})
|
||||||
|
|
||||||
|
b.AssertFileContent("public/index.html", `
|
||||||
|
Param from module: Rocks|
|
||||||
|
JS imported in module: |
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bep) this fails when testmodBuilder is also building ...
|
// TODO(bep) this fails when testmodBuilder is also building ...
|
||||||
func TestHugoModules(t *testing.T) {
|
func TestHugoModulesMatrix(t *testing.T) {
|
||||||
if !isCI() {
|
if !isCI() {
|
||||||
t.Skip("skip (relative) long running modules test when running locally")
|
t.Skip("skip (relative) long running modules test when running locally")
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,7 +219,7 @@ func (c *Client) Vendor() error {
|
||||||
// This is the project.
|
// This is the project.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// We respect the --ignoreVendor flag even for the vendor command.
|
|
||||||
if !t.IsGoMod() && !t.Vendor() {
|
if !t.IsGoMod() && !t.Vendor() {
|
||||||
// We currently do not vendor components living in the
|
// We currently do not vendor components living in the
|
||||||
// theme directory, see https://github.com/gohugoio/hugo/issues/5993
|
// theme directory, see https://github.com/gohugoio/hugo/issues/5993
|
||||||
|
|
|
@ -339,7 +339,7 @@ func (c *collector) addAndRecurse(owner *moduleAdapter, disabled bool) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if tc == nil {
|
if tc == nil || moduleImport.IgnoreImports {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := c.addAndRecurse(tc, disabled); err != nil {
|
if err := c.addAndRecurse(tc, disabled); err != nil {
|
||||||
|
|
|
@ -302,7 +302,9 @@ func (v HugoVersion) IsValid() bool {
|
||||||
|
|
||||||
type Import struct {
|
type Import struct {
|
||||||
Path string // Module path
|
Path string // Module path
|
||||||
IgnoreConfig bool // Ignore any config.toml found.
|
IgnoreConfig bool // Ignore any config in config.toml (will still folow imports).
|
||||||
|
IgnoreImports bool // Do not follow any configured imports.
|
||||||
|
NoVendor bool // Never vendor this import (only allowed in main project).
|
||||||
Disable bool // Turn off this module.
|
Disable bool // Turn off this module.
|
||||||
Mounts []Mount
|
Mounts []Mount
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue