cfg := config.New()
cfg.Set("renderToDisk", (c.s == nil && !c.r.renderToMemory) || (c.s != nil && c.s.renderToDisk))
watch := c.r.buildWatch || (c.s != nil && c.s.serverWatch)
- cfg.Set("environment", c.r.environment)
+ if c.r.environment != "" {
+ cfg.Set("environment", c.r.environment)
+ }
cfg.Set("internal", maps.Params{
"running": running,
// version of go that the Hugo binary was built with
GoVersion string
+ conf ConfigProvider
deps []*Dependency
}
return IsExtended
}
+// WorkingDir returns the project working directory.
+func (i HugoInfo) WorkingDir() string {
+ return i.conf.WorkingDir()
+}
+
// Deps gets a list of dependencies for this Hugo build.
func (i HugoInfo) Deps() []*Dependency {
return i.deps
}
+// ConfigProvider represents the config options that are relevant for HugoInfo.
+type ConfigProvider interface {
+ Environment() string
+ WorkingDir() string
+}
+
// NewInfo creates a new Hugo Info object.
-func NewInfo(environment string, deps []*Dependency) HugoInfo {
- if environment == "" {
- environment = EnvironmentProduction
+func NewInfo(conf ConfigProvider, deps []*Dependency) HugoInfo {
+ if conf.Environment() == "" {
+ panic("environment not set")
}
var (
commitHash string
return HugoInfo{
CommitHash: commitHash,
BuildDate: buildDate,
- Environment: environment,
+ Environment: conf.Environment(),
+ conf: conf,
deps: deps,
GoVersion: goVersion,
}
func TestHugoInfo(t *testing.T) {
c := qt.New(t)
- hugoInfo := NewInfo("", nil)
+ conf := testConfig{environment: "production", workingDir: "/mywork"}
+ hugoInfo := NewInfo(conf, nil)
c.Assert(hugoInfo.Version(), qt.Equals, CurrentVersion.Version())
c.Assert(fmt.Sprintf("%T", VersionString("")), qt.Equals, fmt.Sprintf("%T", hugoInfo.Version()))
+ c.Assert(hugoInfo.WorkingDir(), qt.Equals, "/mywork")
bi := getBuildInfo()
if bi != nil {
c.Assert(hugoInfo.IsProduction(), qt.Equals, true)
c.Assert(hugoInfo.IsExtended(), qt.Equals, IsExtended)
- devHugoInfo := NewInfo("development", nil)
+ devHugoInfo := NewInfo(testConfig{environment: "development"}, nil)
c.Assert(devHugoInfo.IsProduction(), qt.Equals, false)
}
+
+type testConfig struct {
+ environment string
+ workingDir string
+}
+
+func (c testConfig) Environment() string {
+ return c.environment
+}
+
+func (c testConfig) WorkingDir() string {
+ return c.workingDir
+}
return c.m.Base.CommonDirs
}
+func (c ConfigLanguage) WorkingDir() string {
+ return c.m.Base.WorkingDir
+}
+
func (c ConfigLanguage) Quiet() bool {
return c.m.Base.Internal.Quiet
}
Timeout() time.Duration
StaticDirs() []string
IgnoredErrors() map[string]bool
+ WorkingDir() string
}
// Provider provides the configuration settings for Hugo.
}
+func TestConfigHugoWorkingDir(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+-- layouts/index.html --
+WorkingDir: {{ hugo.WorkingDir }}|
+
+`
+ b := NewIntegrationTestBuilder(
+ IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ WorkingDir: "myworkingdir",
+ },
+ ).Build()
+
+ b.AssertFileContent("public/index.html", `
+WorkingDir: myworkingdir|
+`)
+
+}
+
func TestConfigMergeLanguageDeepEmptyLefSide(t *testing.T) {
t.Parallel()
dependencies = append(dependencies, depFromMod(m))
}
- h.hugoInfo = hugo.NewInfo(h.Configs.Base.Environment, dependencies)
+ h.hugoInfo = hugo.NewInfo(h.Configs.GetFirstLanguageConfig(), dependencies)
var prototype *deps.Deps
for i, s := range sites {
translationProvider := NewTranslationProvider()
d.TemplateProvider = tplimpl.DefaultTemplateProvider
d.TranslationProvider = translationProvider
- d.Site = page.NewDummyHugoSite(cfg)
+ d.Site = page.NewDummyHugoSite(d.Conf)
if err := d.Compile(nil); err != nil {
panic(err)
}
func TestPageMatcher(t *testing.T) {
c := qt.New(t)
- developmentTestSite := testSite{h: hugo.NewInfo("development", nil)}
- productionTestSite := testSite{h: hugo.NewInfo("production", nil)}
+ developmentTestSite := testSite{h: hugo.NewInfo(testConfig{environment: "development"}, nil)}
+ productionTestSite := testSite{h: hugo.NewInfo(testConfig{environment: "production"}, nil)}
p1, p2, p3 :=
&testPage{path: "/p1", kind: "section", lang: "en", site: developmentTestSite},
c.Assert(got, qt.IsNotNil)
}
+
+type testConfig struct {
+ environment string
+ workingDir string
+}
+
+func (c testConfig) Environment() string {
+ return c.environment
+}
+
+func (c testConfig) WorkingDir() string {
+ return c.workingDir
+}
}
// NewDummyHugoSite creates a new minimal test site.
-func NewDummyHugoSite(cfg config.Provider) Site {
+func NewDummyHugoSite(conf config.AllProvider) Site {
return testSite{
- h: hugo.NewInfo(hugo.EnvironmentProduction, nil),
+ h: hugo.NewInfo(conf, nil),
l: &langs.Language{
Lang: "en",
},
if err := d.Init(); err != nil {
panic(err)
}
- d.Site = page.NewDummyHugoSite(newTestConfig())
+ conf := testconfig.GetTestConfig(nil, newTestConfig())
+ d.Site = page.NewDummyHugoSite(conf)
var namespaces internal.TemplateFuncsNamespaces