diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-12-19 12:17:44 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-12-19 18:51:59 +0100 |
commit | ad6504e6b504277bbc7b60d093cdccd4f3baaa4f (patch) | |
tree | 294ef0155dcd9b884fa387512b2b54ab0ef1493e /hugolib | |
parent | 158e7ec204e5149d77893d353cac9f55946d3e9a (diff) |
Fix abs path handling in module mounts
Fixes #6622
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/filesystems/basefs.go | 3 | ||||
-rw-r--r-- | hugolib/hugo_modules_test.go | 54 | ||||
-rw-r--r-- | hugolib/resource_chain_test.go | 8 |
3 files changed, 61 insertions, 4 deletions
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index cdc39ce61..d931db4d1 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -531,6 +531,9 @@ func (b *sourceFilesystemsBuilder) createModFs( ) absPathify := func(path string) string { + if filepath.IsAbs(path) { + return path + } return paths.AbsPathify(md.dir, path) } diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go index 900443275..929bd7ab1 100644 --- a/hugolib/hugo_modules_test.go +++ b/hugolib/hugo_modules_test.go @@ -569,3 +569,57 @@ func TestSiteWithGoModButNoModules(t *testing.T) { b.Build(BuildCfg{}) } + +// https://github.com/gohugoio/hugo/issues/6622 +func TestModuleAbsMount(t *testing.T) { + t.Parallel() + + c := qt.New(t) + // We need to use the OS fs for this. + workDir, clean1, err := htesting.CreateTempDir(hugofs.Os, "hugo-project") + c.Assert(err, qt.IsNil) + absContentDir, clean2, err := htesting.CreateTempDir(hugofs.Os, "hugo-content") + c.Assert(err, qt.IsNil) + + cfg := viper.New() + cfg.Set("workingDir", workDir) + fs := hugofs.NewFrom(hugofs.Os, cfg) + + config := fmt.Sprintf(` +workingDir=%q + +[module] + [[module.mounts]] + source = %q + target = "content" + +`, workDir, absContentDir) + + defer clean1() + defer clean2() + + b := newTestSitesBuilder(t) + b.Fs = fs + + contentFilename := filepath.Join(absContentDir, "p1.md") + afero.WriteFile(hugofs.Os, contentFilename, []byte(` +--- +title: Abs +--- + +Content. +`), 0777) + + b.WithWorkingDir(workDir).WithConfigFile("toml", config) + b.WithContent("dummy.md", "") + + b.WithTemplatesAdded("index.html", ` +{{ $p1 := site.GetPage "p1" }} +P1: {{ $p1.Title }}|{{ $p1.RelPermalink }}|Filename: {{ $p1.File.Filename }} +`) + + b.Build(BuildCfg{}) + + b.AssertFileContent("public/index.html", "P1: Abs|/p1/", "Filename: "+contentFilename) + +} diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go index 9d869ba41..9590fc5de 100644 --- a/hugolib/resource_chain_test.go +++ b/hugolib/resource_chain_test.go @@ -87,9 +87,9 @@ func TestSCSSWithThemeOverrides(t *testing.T) { t.Skip("Skip SCSS") } c := qt.New(t) - workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-scss-include") + workDir, clean1, err := htesting.CreateTempDir(hugofs.Os, "hugo-scss-include") c.Assert(err, qt.IsNil) - defer clean() + defer clean1() theme := "mytheme" themesDir := filepath.Join(workDir, "themes") @@ -174,9 +174,9 @@ func TestSCSSWithIncludePathsSass(t *testing.T) { t.Skip("Skip SCSS") } c := qt.New(t) - workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-scss-includepaths") + workDir, clean1, err := htesting.CreateTempDir(hugofs.Os, "hugo-scss-includepaths") c.Assert(err, qt.IsNil) - defer clean() + defer clean1() v := viper.New() v.Set("workingDir", workDir) |