summaryrefslogtreecommitdiffstats
path: root/hugolib/hugo_modules_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-12-30 10:50:00 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-01-01 18:19:49 +0100
commitff6253bc7cf745e9c0127ddc9006da3c2c00c738 (patch)
tree9e80cc607575e516f4f93e0f16c3e82df3bafdb5 /hugolib/hugo_modules_test.go
parentaa4ccb8a1e9b8aa17397acf34049a2aa16b0b6cb (diff)
Support files in content mounts
This commit is a general improvement of handling if single file mounts. Fixes #6684 Fixes #6696
Diffstat (limited to 'hugolib/hugo_modules_test.go')
-rw-r--r--hugolib/hugo_modules_test.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go
index 929bd7ab1..1c665e6e3 100644
--- a/hugolib/hugo_modules_test.go
+++ b/hugolib/hugo_modules_test.go
@@ -545,6 +545,85 @@ title: "My Page"
b.AssertFileContent("public/mypage/index.html", "Permalink: https://example.org/mypage/")
}
+// https://github.com/gohugoio/hugo/issues/6684
+func TestMountsContentFile(t *testing.T) {
+ c := qt.New(t)
+ workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-content-file")
+ c.Assert(err, qt.IsNil)
+ defer clean()
+
+ configTemplate := `
+baseURL = "https://example.com"
+title = "My Modular Site"
+workingDir = %q
+
+[module]
+ [[module.mounts]]
+ source = "README.md"
+ target = "content/_index.md"
+ [[module.mounts]]
+ source = "mycontent"
+ target = "content/blog"
+
+`
+
+ config := fmt.Sprintf(configTemplate, workingDir)
+
+ b := newTestSitesBuilder(t).Running()
+
+ b.Fs = hugofs.NewDefault(viper.New())
+
+ b.WithWorkingDir(workingDir).WithConfigFile("toml", config)
+ b.WithTemplatesAdded("index.html", `
+{{ .Title }}
+{{ .Content }}
+
+{{ $readme := .Site.GetPage "/README.md" }}
+{{ with $readme }}README: {{ .Title }}|Filename: {{ path.Join .File.Filename }}|Path: {{ path.Join .File.Path }}|FilePath: {{ path.Join .File.FileInfo.Meta.PathFile }}|{{ end }}
+
+
+{{ $mypage := .Site.GetPage "/blog/mypage.md" }}
+{{ with $mypage }}MYPAGE: {{ .Title }}|Path: {{ path.Join .File.Path }}|FilePath: {{ path.Join .File.FileInfo.Meta.PathFile }}|{{ end }}
+
+`)
+
+ os.Mkdir(filepath.Join(workingDir, "mycontent"), 0777)
+
+ b.WithSourceFile("README.md", `---
+title: "Readme Title"
+---
+
+Readme Content.
+`,
+ filepath.Join("mycontent", "mypage.md"), `
+---
+title: "My Page"
+---
+
+`)
+
+ b.Build(BuildCfg{})
+
+ b.AssertFileContent("public/index.html", `
+README: Readme Title
+/README.md|Path: _index.md|FilePath: README.md
+Readme Content.
+MYPAGE: My Page|Path: blog/mypage.md|FilePath: mycontent/mypage.md|
+`)
+ b.AssertFileContent("public/blog/mypage/index.html", "Single: My Page")
+
+ b.EditFiles("README.md", `---
+title: "Readme Edit"
+---
+`)
+
+ b.Build(BuildCfg{})
+
+ b.AssertFileContent("public/index.html", `
+Readme Edit
+`)
+}
+
// https://github.com/gohugoio/hugo/issues/6299
func TestSiteWithGoModButNoModules(t *testing.T) {
t.Parallel()