]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
hugolib: Display server address after each rebuild
authorJoe Mooring <joe.mooring@veriphor.com>
Sat, 13 Apr 2024 16:22:19 +0000 (09:22 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 13 Apr 2024 20:16:00 +0000 (22:16 +0200)
Closes #12359

commands/server.go
config/allconfig/allconfig.go
hugolib/hugo_sites_build.go

index 09fb4e79f7e1275535fd03d06a76aca8cddaef35..ccd2bde7d75911ad27ffc2022fc599a83c8efed3 100644 (file)
@@ -237,9 +237,8 @@ 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\n", f.c.hugoTry().Deps.Site.Hugo().Environment)
-
        if i == 0 {
+               r.Printf("Environment: %q\n", f.c.hugoTry().Deps.Site.Hugo().Environment)
                mainTarget := "disk"
                if f.c.r.renderToMemory {
                        mainTarget = "memory"
@@ -569,7 +568,7 @@ func (c *serverCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
                                }
                        }
 
-                       if err := c.setBaseURLsInConfig(); err != nil {
+                       if err := c.setServerInfoInConfig(); err != nil {
                                return err
                        }
 
@@ -614,7 +613,7 @@ func (c *serverCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
        return nil
 }
 
-func (c *serverCommand) setBaseURLsInConfig() error {
+func (c *serverCommand) setServerInfoInConfig() error {
        if len(c.serverPorts) == 0 {
                panic("no server ports set")
        }
@@ -641,7 +640,8 @@ func (c *serverCommand) setBaseURLsInConfig() error {
                        if c.liveReloadPort != -1 {
                                baseURLLiveReload, _ = baseURLLiveReload.WithPort(c.liveReloadPort)
                        }
-                       langConfig.C.SetBaseURL(baseURL, baseURLLiveReload)
+                       langConfig.C.SetServerInfo(baseURL, baseURLLiveReload, c.serverInterface)
+
                }
                return nil
        })
index f0e72dabc065e341da1bd02b3330c910199c498b..d5d3dc4e7faa6c1b57e43998a0cf84ff2d541966 100644 (file)
@@ -400,6 +400,7 @@ type ConfigCompiled struct {
        Timeout           time.Duration
        BaseURL           urls.BaseURL
        BaseURLLiveReload urls.BaseURL
+       ServerInterface   string
        KindOutputFormats map[string]output.Formats
        DisabledKinds     map[string]bool
        DisabledLanguages map[string]bool
@@ -434,9 +435,10 @@ func (c *ConfigCompiled) IsMainSectionsSet() bool {
 }
 
 // This is set after the config is compiled by the server command.
-func (c *ConfigCompiled) SetBaseURL(baseURL, baseURLLiveReload urls.BaseURL) {
+func (c *ConfigCompiled) SetServerInfo(baseURL, baseURLLiveReload urls.BaseURL, serverInterface string) {
        c.BaseURL = baseURL
        c.BaseURLLiveReload = baseURLLiveReload
+       c.ServerInterface = serverInterface
 }
 
 // RootConfig holds all the top-level configuration options in Hugo
index 1399e22d2a433af8eb12f9497123c2e32309264c..a77900e2753e474000de1b93463da8fc0679f215 100644 (file)
@@ -919,9 +919,22 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
                }
        }
 
+       h.logServerAddresses()
+
        return nil
 }
 
+func (h *HugoSites) logServerAddresses() {
+       if h.hugoInfo.IsMultihost() {
+               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)
+               }
+       } else {
+               s := h.Sites[0]
+               h.Log.Printf("Web Server is available at %s (bind address %s)\n", s.conf.C.BaseURL, s.conf.C.ServerInterface)
+       }
+}
+
 func (h *HugoSites) processFull(ctx context.Context, l logg.LevelLogger, config BuildCfg) (err error) {
        if err = h.processFiles(ctx, l, config); err != nil {
                err = fmt.Errorf("readAndProcessContent: %w", err)