Skip to content

Commit

Permalink
Add hugo.WorkingDir
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed May 20, 2023
1 parent 4f085e8 commit 3f7de92
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
14 changes: 9 additions & 5 deletions common/hugo/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type HugoInfo struct {
// version of go that the Hugo binary was built with
GoVersion string

conf config.AllProvider
deps []*Dependency
}

Expand All @@ -81,16 +82,18 @@ func (i HugoInfo) IsExtended() bool {
return IsExtended
}

// WorkingDir returns the project working directory.
func (i HugoInfo) WorkingDir() string {
return i.conf.BaseConfig().WorkingDir
}

// Deps gets a list of dependencies for this Hugo build.
func (i HugoInfo) Deps() []*Dependency {
return i.deps
}

// NewInfo creates a new Hugo Info object.
func NewInfo(environment string, deps []*Dependency) HugoInfo {
if environment == "" {
environment = EnvironmentProduction
}
func NewInfo(conf config.AllProvider, deps []*Dependency) HugoInfo {
var (
commitHash string
buildDate string
Expand All @@ -107,7 +110,8 @@ func NewInfo(environment string, deps []*Dependency) HugoInfo {
return HugoInfo{
CommitHash: commitHash,
BuildDate: buildDate,
Environment: environment,
Environment: conf.Environment(),
conf: conf,
deps: deps,
GoVersion: goVersion,
}
Expand Down
23 changes: 23 additions & 0 deletions hugolib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,29 @@ mainSections: []

}

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()

Expand Down
2 changes: 1 addition & 1 deletion hugolib/site_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func newHugoSitesNew(cfg deps.DepsCfg, d *deps.Deps, sites []*Site) (*HugoSites,
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 {
Expand Down
4 changes: 2 additions & 2 deletions resources/page/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,9 @@ func (s testSite) Param(key any) (any, error) {
}

// 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",
},
Expand Down
3 changes: 2 additions & 1 deletion tpl/cast/docshelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func init() {
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

Expand Down

0 comments on commit 3f7de92

Please sign in to comment.