commands: Make sure the hugo field is always initialized before it's used

Wrap the field to make it accessible after initialization.

Fixes #6193
This commit is contained in:
HyeonGyu Lee
2019-08-15 16:33:47 +09:00
committed by Bjørn Erik Pedersen
parent 37f5929803
commit ea9261e856
8 changed files with 54 additions and 40 deletions

View File

@@ -244,7 +244,7 @@ func (sc *serverCmd) server(cmd *cobra.Command, args []string) error {
return err
}
for _, s := range c.hugo.Sites {
for _, s := range c.hugo().Sites {
s.RegisterMediaTypes()
}
@@ -303,9 +303,9 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, string, string, erro
publishDir = filepath.Join(publishDir, root)
}
absPublishDir := f.c.hugo.PathSpec.AbsPathify(publishDir)
absPublishDir := f.c.hugo().PathSpec.AbsPathify(publishDir)
jww.FEEDBACK.Printf("Environment: %q", f.c.hugo.Deps.Site.Hugo().Environment)
jww.FEEDBACK.Printf("Environment: %q", f.c.hugo().Deps.Site.Hugo().Environment)
if i == 0 {
if f.s.renderToDisk {
@@ -398,7 +398,7 @@ func removeErrorPrefixFromLog(content string) string {
}
func (c *commandeer) serve(s *serverCmd) error {
isMultiHost := c.hugo.IsMultihost()
isMultiHost := c.hugo().IsMultihost()
var (
baseURLs []string
@@ -406,17 +406,17 @@ func (c *commandeer) serve(s *serverCmd) error {
)
if isMultiHost {
for _, s := range c.hugo.Sites {
for _, s := range c.hugo().Sites {
baseURLs = append(baseURLs, s.BaseURL.String())
roots = append(roots, s.Language().Lang)
}
} else {
s := c.hugo.Sites[0]
s := c.hugo().Sites[0]
baseURLs = []string{s.BaseURL.String()}
roots = []string{""}
}
templ, err := c.hugo.TextTmpl.Parse("__default_server_error", buildErrorTemplate)
templ, err := c.hugo().TextTmpl.Parse("__default_server_error", buildErrorTemplate)
if err != nil {
return err
}