Skip to content

Commit

Permalink
Fix regression with site.IsServer when not running a server
Browse files Browse the repository at this point in the history
Fixes #11006
  • Loading branch information
bep committed May 24, 2023
1 parent 99407c3 commit 9a235d0
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion commands/commandeer.go
Expand Up @@ -339,7 +339,7 @@ func (r *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args

b := newHugoBuilder(r, nil)

if err := b.loadConfig(cd, true); err != nil {
if err := b.loadConfig(cd, false); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion commands/server.go
Expand Up @@ -204,7 +204,7 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, net.Listener, string
listener := f.c.serverPorts[i].ln
logger := f.c.r.logger

r.Printf("Environment: %q", f.c.hugoTry().Deps.Site.Hugo().Environment)
r.Printf("Environment: %q\n", f.c.hugoTry().Deps.Site.Hugo().Environment)

if i == 0 {
if f.c.renderToDisk {
Expand Down
2 changes: 1 addition & 1 deletion hugolib/hugo_sites_build.go
Expand Up @@ -185,7 +185,7 @@ func (h *HugoSites) initRebuild(config *BuildCfg) error {
return errors.New("rebuild does not support 'ResetState'")
}

if !h.Configs.Base.Internal.Running {
if !h.Configs.Base.Internal.Watch {
return errors.New("rebuild called when not in watch mode")
}

Expand Down
1 change: 1 addition & 0 deletions hugolib/integrationtest_builder.go
Expand Up @@ -327,6 +327,7 @@ func (s *IntegrationTestBuilder) initBuilder() error {
if s.Cfg.Running {
flags.Set("internal", maps.Params{
"running": s.Cfg.Running,
"watch": s.Cfg.Running,
})
}

Expand Down
2 changes: 1 addition & 1 deletion hugolib/page.go
Expand Up @@ -583,7 +583,7 @@ var defaultRenderStringOpts = renderStringOpts{
}

func (p *pageState) addDependency(dep identity.Provider) {
if !p.s.running() || p.pageOutput.cp == nil {
if !p.s.watching() || p.pageOutput.cp == nil {
return
}
p.pageOutput.cp.dependencyTracker.Add(dep)
Expand Down
2 changes: 1 addition & 1 deletion hugolib/page__per_output.go
Expand Up @@ -76,7 +76,7 @@ func newPageContentOutput(p *pageState, po *pageOutput) (*pageContentOutput, err
parent := p.init

var dependencyTracker identity.Manager
if p.s.running() {
if p.s.watching() {
dependencyTracker = identity.NewManager(pageContentOutputDependenciesID)
}

Expand Down
6 changes: 3 additions & 3 deletions hugolib/site.go
Expand Up @@ -389,8 +389,8 @@ func (s *siteRefLinker) refLink(ref string, source any, relative bool, outputFor
return link, nil
}

func (s *Site) running() bool {
return s.h != nil && s.h.Configs.Base.Internal.Running
func (s *Site) watching() bool {
return s.h != nil && s.h.Configs.Base.Internal.Watch
}

type whatChanged struct {
Expand Down Expand Up @@ -1064,7 +1064,7 @@ func (s *Site) renderAndWritePage(statCounter *uint64, name string, targetPath s
pd.AbsURLPath = s.absURLPath(targetPath)
}

if s.running() && s.conf.Internal.Watch && !s.conf.Internal.DisableLiveReload {
if s.watching() && s.conf.Internal.Watch && !s.conf.Internal.DisableLiveReload {
pd.LiveReloadBaseURL = s.Conf.BaseURLLiveReload().URL()
}

Expand Down
2 changes: 1 addition & 1 deletion hugolib/site_new.go
Expand Up @@ -280,7 +280,7 @@ func newHugoSitesNew(cfg deps.DepsCfg, d *deps.Deps, sites []*Site) (*HugoSites,
}

// Only needed in server mode.
if cfg.Configs.Base.Internal.Running {
if cfg.Configs.Base.Internal.Watch {
h.ContentChanges = &contentChangeMap{
pathSpec: h.PathSpec,
symContent: make(map[string]map[string]bool),
Expand Down
1 change: 1 addition & 0 deletions hugolib/testhelpers_test.go
Expand Up @@ -486,6 +486,7 @@ func (s *sitesBuilder) LoadConfig() error {
flags := config.New()
flags.Set("internal", map[string]any{
"running": s.running,
"watch": s.running,
})

if s.workingDir != "" {
Expand Down
3 changes: 2 additions & 1 deletion testscripts/commands/hugo.txt
Expand Up @@ -5,12 +5,13 @@ stdout 'Pages.*|1'
stdout 'Total in'
checkfile public/index.html
checkfile public/p1/index.html
grep 'IsServer: false' public/index.html

-- hugo.toml --
baseURL = "http://example.org/"
disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"]
-- layouts/index.html --
Home.
Home|IsServer: {{ .Site.IsServer }}|
-- layouts/_default/single.html --
Title: {{ .Title }}
-- content/p1.md --
Expand Down

0 comments on commit 9a235d0

Please sign in to comment.