summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-01-31 17:15:14 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-02-04 00:17:10 +0100
commit80dd6ddde27ce36f5432fb780e94d4974b5277c7 (patch)
tree99d0ba7eb2b343b4b65c4433a998d73af3182933 /hugolib
parent299731012441378bb9c057ceb0a3c277108aaf01 (diff)
Fix module mount in sub folder
This addresses a specific issue, but is a also a major simplification of the filesystem file mounts. Fixes #6730
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/filesystems/basefs.go1
-rw-r--r--hugolib/filesystems/basefs_test.go2
-rw-r--r--hugolib/hugo_modules_test.go45
3 files changed, 46 insertions, 2 deletions
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go
index 5cede88d0..34770520f 100644
--- a/hugolib/filesystems/basefs.go
+++ b/hugolib/filesystems/basefs.go
@@ -258,6 +258,7 @@ func (s SourceFilesystems) MakeStaticPathRelative(filename string) string {
// MakePathRelative creates a relative path from the given filename.
// It will return an empty string if the filename is not a member of this filesystem.
func (d *SourceFilesystem) MakePathRelative(filename string) string {
+
for _, dir := range d.Dirs {
meta := dir.(hugofs.FileMetaInfo).Meta()
currentPath := meta.Filename()
diff --git a/hugolib/filesystems/basefs_test.go b/hugolib/filesystems/basefs_test.go
index 3cac4f11a..a0e9f0020 100644
--- a/hugolib/filesystems/basefs_test.go
+++ b/hugolib/filesystems/basefs_test.go
@@ -173,9 +173,7 @@ theme = ["atheme"]
filename = filepath.FromSlash(filename)
f, err := fs.Open(filename)
c.Assert(err, qt.IsNil)
- name := f.Name()
f.Close()
- c.Assert(name, qt.Equals, filename)
}
}
}
diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go
index 4b71a54c8..65d232208 100644
--- a/hugolib/hugo_modules_test.go
+++ b/hugolib/hugo_modules_test.go
@@ -38,6 +38,47 @@ import (
"github.com/spf13/viper"
)
+// https://github.com/gohugoio/hugo/issues/6730
+func TestHugoModulesTargetInSubFolder(t *testing.T) {
+ config := `
+baseURL="https://example.org"
+workingDir = %q
+
+[module]
+[[module.imports]]
+path="github.com/gohugoio/hugoTestModule2"
+ [[module.imports.mounts]]
+ source = "templates/hooks"
+ target = "layouts/_default/_markup"
+
+`
+
+ b := newTestSitesBuilder(t)
+ workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-target-in-subfolder-test")
+ b.Assert(err, qt.IsNil)
+ defer clean()
+ b.Fs = hugofs.NewDefault(viper.New())
+ b.WithWorkingDir(workingDir).WithConfigFile("toml", fmt.Sprintf(config, workingDir))
+ b.WithTemplates("_default/single.html", `{{ .Content }}`)
+ b.WithContent("p1.md", `---
+title: "Page"
+---
+
+[A link](https://bep.is)
+
+`)
+ b.WithSourceFile("go.mod", `
+module github.com/gohugoio/tests/testHugoModules
+
+
+`)
+
+ b.Build(BuildCfg{})
+
+ b.AssertFileContent("public/p1/index.html", `<p>Page|https://bep.is|Title: |Text: A link|END</p>`)
+
+}
+
// TODO(bep) this fails when testmodBuilder is also building ...
func TestHugoModules(t *testing.T) {
if !isCI() {
@@ -588,6 +629,9 @@ workingDir = %q
{{ $mypage := .Site.GetPage "/blog/mypage.md" }}
{{ with $mypage }}MYPAGE: {{ .Title }}|Path: {{ path.Join .File.Path }}|FilePath: {{ path.Join .File.FileInfo.Meta.PathFile }}|{{ end }}
+{{ $mybundle := .Site.GetPage "/blog/mybundle" }}
+{{ with $mybundle }}MYBUNDLE: {{ .Title }}|Path: {{ path.Join .File.Path }}|FilePath: {{ path.Join .File.FileInfo.Meta.PathFile }}|{{ end }}
+
`, "_default/_markup/render-link.html", `
{{ $link := .Destination }}
@@ -640,6 +684,7 @@ README: Readme Title
/README.md|Path: _index.md|FilePath: README.md
Readme Content.
MYPAGE: My Page|Path: blog/mypage.md|FilePath: mycontent/mypage.md|
+MYBUNDLE: My Bundle|Path: blog/mybundle/index.md|FilePath: mycontent/mybundle/index.md|
`)
b.AssertFileContent("public/blog/mypage/index.html", `
<a href="https://example.com/blog/mybundle/">Relative Link From Page</a>