Skip to content

Commit 9a235d0

Browse files
committedMay 24, 2023
Fix regression with site.IsServer when not running a server
Fixes #11006
1 parent 99407c3 commit 9a235d0

10 files changed

+13
-10
lines changed
 

‎commands/commandeer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (r *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args
339339

340340
b := newHugoBuilder(r, nil)
341341

342-
if err := b.loadConfig(cd, true); err != nil {
342+
if err := b.loadConfig(cd, false); err != nil {
343343
return err
344344
}
345345

‎commands/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, net.Listener, string
204204
listener := f.c.serverPorts[i].ln
205205
logger := f.c.r.logger
206206

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

209209
if i == 0 {
210210
if f.c.renderToDisk {

‎hugolib/hugo_sites_build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (h *HugoSites) initRebuild(config *BuildCfg) error {
185185
return errors.New("rebuild does not support 'ResetState'")
186186
}
187187

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

‎hugolib/integrationtest_builder.go

+1
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ func (s *IntegrationTestBuilder) initBuilder() error {
327327
if s.Cfg.Running {
328328
flags.Set("internal", maps.Params{
329329
"running": s.Cfg.Running,
330+
"watch": s.Cfg.Running,
330331
})
331332
}
332333

‎hugolib/page.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ var defaultRenderStringOpts = renderStringOpts{
583583
}
584584

585585
func (p *pageState) addDependency(dep identity.Provider) {
586-
if !p.s.running() || p.pageOutput.cp == nil {
586+
if !p.s.watching() || p.pageOutput.cp == nil {
587587
return
588588
}
589589
p.pageOutput.cp.dependencyTracker.Add(dep)

‎hugolib/page__per_output.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func newPageContentOutput(p *pageState, po *pageOutput) (*pageContentOutput, err
7676
parent := p.init
7777

7878
var dependencyTracker identity.Manager
79-
if p.s.running() {
79+
if p.s.watching() {
8080
dependencyTracker = identity.NewManager(pageContentOutputDependenciesID)
8181
}
8282

‎hugolib/site.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ func (s *siteRefLinker) refLink(ref string, source any, relative bool, outputFor
389389
return link, nil
390390
}
391391

392-
func (s *Site) running() bool {
393-
return s.h != nil && s.h.Configs.Base.Internal.Running
392+
func (s *Site) watching() bool {
393+
return s.h != nil && s.h.Configs.Base.Internal.Watch
394394
}
395395

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

1067-
if s.running() && s.conf.Internal.Watch && !s.conf.Internal.DisableLiveReload {
1067+
if s.watching() && s.conf.Internal.Watch && !s.conf.Internal.DisableLiveReload {
10681068
pd.LiveReloadBaseURL = s.Conf.BaseURLLiveReload().URL()
10691069
}
10701070

‎hugolib/site_new.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func newHugoSitesNew(cfg deps.DepsCfg, d *deps.Deps, sites []*Site) (*HugoSites,
280280
}
281281

282282
// Only needed in server mode.
283-
if cfg.Configs.Base.Internal.Running {
283+
if cfg.Configs.Base.Internal.Watch {
284284
h.ContentChanges = &contentChangeMap{
285285
pathSpec: h.PathSpec,
286286
symContent: make(map[string]map[string]bool),

‎hugolib/testhelpers_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ func (s *sitesBuilder) LoadConfig() error {
486486
flags := config.New()
487487
flags.Set("internal", map[string]any{
488488
"running": s.running,
489+
"watch": s.running,
489490
})
490491

491492
if s.workingDir != "" {

‎testscripts/commands/hugo.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ stdout 'Pages.*|1'
55
stdout 'Total in'
66
checkfile public/index.html
77
checkfile public/p1/index.html
8+
grep 'IsServer: false' public/index.html
89

910
-- hugo.toml --
1011
baseURL = "http://example.org/"
1112
disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"]
1213
-- layouts/index.html --
13-
Home.
14+
Home|IsServer: {{ .Site.IsServer }}|
1415
-- layouts/_default/single.html --
1516
Title: {{ .Title }}
1617
-- content/p1.md --

0 commit comments

Comments
 (0)
Please sign in to comment.