From ff6253bc7cf745e9c0127ddc9006da3c2c00c738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 30 Dec 2019 10:50:00 +0100 Subject: Support files in content mounts This commit is a general improvement of handling if single file mounts. Fixes #6684 Fixes #6696 --- hugolib/hugo_modules_test.go | 79 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'hugolib/hugo_modules_test.go') 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() -- cgit v1.2.3