mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 14:10:31 +03:00
parent
158e7ec204
commit
ad6504e6b5
4 changed files with 71 additions and 6 deletions
|
@ -531,6 +531,9 @@ func (b *sourceFilesystemsBuilder) createModFs(
|
||||||
)
|
)
|
||||||
|
|
||||||
absPathify := func(path string) string {
|
absPathify := func(path string) string {
|
||||||
|
if filepath.IsAbs(path) {
|
||||||
|
return path
|
||||||
|
}
|
||||||
return paths.AbsPathify(md.dir, path)
|
return paths.AbsPathify(md.dir, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -569,3 +569,57 @@ func TestSiteWithGoModButNoModules(t *testing.T) {
|
||||||
b.Build(BuildCfg{})
|
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)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -87,9 +87,9 @@ func TestSCSSWithThemeOverrides(t *testing.T) {
|
||||||
t.Skip("Skip SCSS")
|
t.Skip("Skip SCSS")
|
||||||
}
|
}
|
||||||
c := qt.New(t)
|
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)
|
c.Assert(err, qt.IsNil)
|
||||||
defer clean()
|
defer clean1()
|
||||||
|
|
||||||
theme := "mytheme"
|
theme := "mytheme"
|
||||||
themesDir := filepath.Join(workDir, "themes")
|
themesDir := filepath.Join(workDir, "themes")
|
||||||
|
@ -174,9 +174,9 @@ func TestSCSSWithIncludePathsSass(t *testing.T) {
|
||||||
t.Skip("Skip SCSS")
|
t.Skip("Skip SCSS")
|
||||||
}
|
}
|
||||||
c := qt.New(t)
|
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)
|
c.Assert(err, qt.IsNil)
|
||||||
defer clean()
|
defer clean1()
|
||||||
|
|
||||||
v := viper.New()
|
v := viper.New()
|
||||||
v.Set("workingDir", workDir)
|
v.Set("workingDir", workDir)
|
||||||
|
|
|
@ -548,7 +548,7 @@ func (c *collector) loadModules() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) normalizeMounts(owner Module, mounts []Mount) ([]Mount, error) {
|
func (c *collector) normalizeMounts(owner *moduleAdapter, mounts []Mount) ([]Mount, error) {
|
||||||
var out []Mount
|
var out []Mount
|
||||||
dir := owner.Dir()
|
dir := owner.Dir()
|
||||||
|
|
||||||
|
@ -562,8 +562,16 @@ func (c *collector) normalizeMounts(owner Module, mounts []Mount) ([]Mount, erro
|
||||||
mnt.Source = filepath.Clean(mnt.Source)
|
mnt.Source = filepath.Clean(mnt.Source)
|
||||||
mnt.Target = filepath.Clean(mnt.Target)
|
mnt.Target = filepath.Clean(mnt.Target)
|
||||||
|
|
||||||
|
var sourceDir string
|
||||||
|
|
||||||
|
if owner.projectMod && filepath.IsAbs(mnt.Source) {
|
||||||
|
// Abs paths in the main project is allowed.
|
||||||
|
sourceDir = mnt.Source
|
||||||
|
} else {
|
||||||
|
sourceDir = filepath.Join(dir, mnt.Source)
|
||||||
|
}
|
||||||
|
|
||||||
// Verify that Source exists
|
// Verify that Source exists
|
||||||
sourceDir := filepath.Join(dir, mnt.Source)
|
|
||||||
_, err := c.fs.Stat(sourceDir)
|
_, err := c.fs.Stat(sourceDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue