mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
commands: Print "Webserver is ..." right before "Total ..."
Also fix it so * It's not printed when running `hugo -w` * It'd printed for all kinds of rebuilds Fixes #12384
This commit is contained in:
parent
9dd687027f
commit
c8e400b621
3 changed files with 19 additions and 9 deletions
|
@ -327,12 +327,12 @@ func (r *rootCommand) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args []string) error {
|
func (r *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args []string) error {
|
||||||
if !r.buildWatch {
|
|
||||||
defer r.timeTrack(time.Now(), "Total")
|
|
||||||
}
|
|
||||||
|
|
||||||
b := newHugoBuilder(r, nil)
|
b := newHugoBuilder(r, nil)
|
||||||
|
|
||||||
|
if !r.buildWatch {
|
||||||
|
defer b.postBuild("Total", time.Now())
|
||||||
|
}
|
||||||
|
|
||||||
if err := b.loadConfig(cd, false); err != nil {
|
if err := b.loadConfig(cd, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,9 +75,14 @@ type hugoBuilder struct {
|
||||||
errState hugoBuilderErrState
|
errState hugoBuilderErrState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var errConfigNotSet = errors.New("config not set")
|
||||||
|
|
||||||
func (c *hugoBuilder) withConfE(fn func(conf *commonConfig) error) error {
|
func (c *hugoBuilder) withConfE(fn func(conf *commonConfig) error) error {
|
||||||
c.confmu.Lock()
|
c.confmu.Lock()
|
||||||
defer c.confmu.Unlock()
|
defer c.confmu.Unlock()
|
||||||
|
if c.conf == nil {
|
||||||
|
return errConfigNotSet
|
||||||
|
}
|
||||||
return fn(c.conf)
|
return fn(c.conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,7 +590,7 @@ func (c *hugoBuilder) fullRebuild(changeType string) {
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
defer c.r.timeTrack(time.Now(), "Rebuilt")
|
defer c.postBuild("Rebuilt", time.Now())
|
||||||
|
|
||||||
err := c.reloadConfig()
|
err := c.reloadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -855,7 +860,7 @@ func (c *hugoBuilder) handleEvents(watcher *watcher.Batcher,
|
||||||
c.changeDetector.PrepareNew()
|
c.changeDetector.PrepareNew()
|
||||||
|
|
||||||
func() {
|
func() {
|
||||||
defer c.r.timeTrack(time.Now(), "Total")
|
defer c.postBuild("Total", time.Now())
|
||||||
if err := c.rebuildSites(dynamicEvents); err != nil {
|
if err := c.rebuildSites(dynamicEvents); err != nil {
|
||||||
c.handleBuildErr(err, "Rebuild failed")
|
c.handleBuildErr(err, "Rebuild failed")
|
||||||
}
|
}
|
||||||
|
@ -901,6 +906,13 @@ func (c *hugoBuilder) handleEvents(watcher *watcher.Batcher,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *hugoBuilder) postBuild(what string, start time.Time) {
|
||||||
|
if h, err := c.hugo(); err == nil && h.Conf.Running() {
|
||||||
|
h.LogServerAddresses()
|
||||||
|
}
|
||||||
|
c.r.timeTrack(start, what)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *hugoBuilder) hugo() (*hugolib.HugoSites, error) {
|
func (c *hugoBuilder) hugo() (*hugolib.HugoSites, error) {
|
||||||
var h *hugolib.HugoSites
|
var h *hugolib.HugoSites
|
||||||
if err := c.withConfE(func(conf *commonConfig) error {
|
if err := c.withConfE(func(conf *commonConfig) error {
|
||||||
|
|
|
@ -951,12 +951,10 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h.logServerAddresses()
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HugoSites) logServerAddresses() {
|
func (h *HugoSites) LogServerAddresses() {
|
||||||
if h.hugoInfo.IsMultihost() {
|
if h.hugoInfo.IsMultihost() {
|
||||||
for _, s := range h.Sites {
|
for _, s := range h.Sites {
|
||||||
h.Log.Printf("Web Server is available at %s (bind address %s) %s\n", s.conf.C.BaseURL, s.conf.C.ServerInterface, s.Language().Lang)
|
h.Log.Printf("Web Server is available at %s (bind address %s) %s\n", s.conf.C.BaseURL, s.conf.C.ServerInterface, s.Language().Lang)
|
||||||
|
|
Loading…
Reference in a new issue