From: Bjørn Erik Pedersen Date: Tue, 30 Jul 2019 11:35:16 +0000 (+0200) Subject: Fix self-mounts on the main project X-Git-Tag: v0.56.3~9 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=36220851e4ed7fc3fa78aa250d001d5f922210e7;p=brevno-suite%2Fhugo Fix self-mounts on the main project Fixes #6143 --- diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go index 73a3d2db..66b3609a 100644 --- a/hugolib/hugo_modules_test.go +++ b/hugolib/hugo_modules_test.go @@ -506,3 +506,31 @@ weight = 2 } } } + +func TestMountsProject(t *testing.T) { + + config := ` + +baseURL="https://example.org" + +[module] +[[module.mounts]] +source="mycontent" +target="content" + +` + b := newTestSitesBuilder(t). + WithConfigFile("toml", config). + WithSourceFile(filepath.Join("mycontent", "mypage.md"), ` +--- +title: "My Page" +--- + +`) + + b.Build(BuildCfg{}) + + //helpers.PrintFs(b.H.Fs.Source, "public", os.Stdout) + + b.AssertFileContent("public/mypage/index.html", "Permalink: https://example.org/mypage/") +} diff --git a/modules/collect.go b/modules/collect.go index 9f3eb99f..5ba7f74e 100644 --- a/modules/collect.go +++ b/modules/collect.go @@ -305,21 +305,25 @@ func (c *collector) addAndRecurse(owner *moduleAdapter, disabled bool) error { func (c *collector) applyMounts(moduleImport Import, mod *moduleAdapter) error { mounts := moduleImport.Mounts - if !mod.projectMod && len(mounts) == 0 { - modConfig := mod.Config() + modConfig := mod.Config() + + if len(mounts) == 0 { + // Mounts not defined by the import. mounts = modConfig.Mounts - if len(mounts) == 0 { - // Create default mount points for every component folder that - // exists in the module. - for _, componentFolder := range files.ComponentFolders { - sourceDir := filepath.Join(mod.Dir(), componentFolder) - _, err := c.fs.Stat(sourceDir) - if err == nil { - mounts = append(mounts, Mount{ - Source: componentFolder, - Target: componentFolder, - }) - } + + } + + if !mod.projectMod && len(mounts) == 0 { + // Create default mount points for every component folder that + // exists in the module. + for _, componentFolder := range files.ComponentFolders { + sourceDir := filepath.Join(mod.Dir(), componentFolder) + _, err := c.fs.Stat(sourceDir) + if err == nil { + mounts = append(mounts, Mount{ + Source: componentFolder, + Target: componentFolder, + }) } } } diff --git a/modules/config.go b/modules/config.go index 122fd6c5..163bc704 100644 --- a/modules/config.go +++ b/modules/config.go @@ -171,6 +171,9 @@ func ApplyProjectConfigDefaults(cfg config.Provider, mod Module) error { mounts = append(mounts, Mount{Source: dirKey.component, Target: dirKey.component}) } + // Prepend the mounts from configuration. + mounts = append(moda.mounts, mounts...) + // Remove duplicates seen := make(map[string]bool) tmp := mounts[:0]