Fix regression with site.IsServer when not running a server

Fixes #11006
This commit is contained in:
Bjørn Erik Pedersen 2023-05-24 09:26:30 +02:00
parent 99407c39ba
commit 9a235d0afc
10 changed files with 13 additions and 10 deletions

View file

@ -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
}

View file

@ -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 {

View file

@ -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")
}

View file

@ -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,
})
}

View file

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

View file

@ -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)
}

View file

@ -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 {
@ -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()
}

View file

@ -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),

View file

@ -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 != "" {

View file

@ -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 --