diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-01-25 10:36:53 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-01-25 10:36:53 +0100 |
commit | 4d912e2aad39bfe8d76672cf53b01317792e02c5 (patch) | |
tree | f94a7106d3c31db330bd76750eb161c82edaf745 | |
parent | 1e27d0589118a114e49c032e4bd68b4798e44a5b (diff) |
hugolib, output: Fix robots.txt in multihost mode
Fixes #4193
-rw-r--r-- | hugolib/site_render.go | 29 | ||||
-rw-r--r-- | output/outputFormat.go | 8 |
2 files changed, 21 insertions, 16 deletions
diff --git a/hugolib/site_render.go b/hugolib/site_render.go index 4848db599..dc94ddce3 100644 --- a/hugolib/site_render.go +++ b/hugolib/site_render.go @@ -19,11 +19,7 @@ import ( "strings" "sync" - "github.com/gohugoio/hugo/helpers" - "github.com/gohugoio/hugo/output" - - bp "github.com/gohugoio/hugo/bufferpool" ) // renderPages renders pages each corresponding to a markdown file. @@ -368,26 +364,27 @@ func (s *Site) renderRobotsTXT() error { return nil } - n := s.newNodePage(kindRobotsTXT) - if err := n.initTargetPathDescriptor(); err != nil { + p := s.newNodePage(kindRobotsTXT) + if err := p.initTargetPathDescriptor(); err != nil { return err } - n.Data["Pages"] = s.Pages - n.Pages = s.Pages + p.Data["Pages"] = s.Pages + p.Pages = s.Pages rLayouts := []string{"robots.txt", "_default/robots.txt", "_internal/_default/robots.txt"} - outBuffer := bp.GetBuffer() - defer bp.PutBuffer(outBuffer) - if err := s.renderForLayouts("robots", n, outBuffer, s.appendThemeTemplates(rLayouts)...); err != nil { - helpers.DistinctWarnLog.Println(err) - return nil + + pageOutput, err := newPageOutput(p, false, output.RobotsTxtFormat) + if err != nil { + return err } - if outBuffer.Len() == 0 { - return nil + targetPath, err := pageOutput.targetPath() + if err != nil { + s.Log.ERROR.Printf("Failed to create target path for page %q: %s", p, err) } - return s.publish(&s.PathSpec.ProcessingStats.Pages, "robots.txt", outBuffer) + return s.renderAndWritePage(&s.PathSpec.ProcessingStats.Pages, "Robots Txt", targetPath, pageOutput, s.appendThemeTemplates(rLayouts)...) + } // renderAliases renders shell pages that simply have a redirect in the header. diff --git a/output/outputFormat.go b/output/outputFormat.go index fbc9f20cc..0920e5736 100644 --- a/output/outputFormat.go +++ b/output/outputFormat.go @@ -125,6 +125,14 @@ var ( Rel: "alternate", } + RobotsTxtFormat = Format{ + Name: "ROBOTS", + MediaType: media.TextType, + BaseName: "robots", + IsPlainText: true, + Rel: "alternate", + } + RSSFormat = Format{ Name: "RSS", MediaType: media.RSSType, |