Add module.replacements

Fixes #7904
Fixes #7908
This commit is contained in:
Bjørn Erik Pedersen
2020-10-29 17:14:04 +01:00
parent 8a1c637c44
commit 173187e263
5 changed files with 146 additions and 25 deletions

View File

@@ -15,6 +15,8 @@ package modules
import (
"bytes"
"os"
"path/filepath"
"testing"
"github.com/gohugoio/hugo/hugofs/glob"
@@ -41,10 +43,14 @@ github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 github.com/gohugoio/h
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, modName)
c.Assert(err, qt.IsNil)
themesDir := filepath.Join(workingDir, "themes")
err = os.Mkdir(themesDir, 0777)
c.Assert(err, qt.IsNil)
ccfg := ClientConfig{
Fs: hugofs.Os,
WorkingDir: workingDir,
ThemesDir: themesDir,
}
withConfig(&ccfg)
@@ -131,6 +137,28 @@ project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor
c.Assert(graphb.String(), qt.Equals, expect)
})
// https://github.com/gohugoio/hugo/issues/7908
c.Run("createThemeDirname", func(c *qt.C) {
mcfg := DefaultModuleConfig
client, clean := newClient(
c, func(cfg *ClientConfig) {
cfg.ModuleConfig = mcfg
})
defer clean()
dirname, err := client.createThemeDirname("foo", false)
c.Assert(err, qt.IsNil)
c.Assert(dirname, qt.Equals, filepath.Join(client.ccfg.ThemesDir, "foo"))
dirname, err = client.createThemeDirname("../../foo", true)
c.Assert(err, qt.IsNil)
c.Assert(dirname, qt.Equals, filepath.Join(client.ccfg.ThemesDir, "../../foo"))
dirname, err = client.createThemeDirname("../../foo", false)
c.Assert(err, qt.Not(qt.IsNil))
})
}
var globAll, _ = glob.GetGlob("**")