diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-03-10 11:45:29 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-03-10 16:57:25 +0100 |
commit | f8dc47eeffa847fd0b51e376da355e3d957848a6 (patch) | |
tree | fd661968ce136ee69159a3560310b65dc8a17fb6 /hugolib/site_output.go | |
parent | ae3fa349de6daf1bbcd09ffc859d6b2e44764795 (diff) |
Allow partial redefinition of the ouputs config
Fixes #4487
Diffstat (limited to 'hugolib/site_output.go')
-rw-r--r-- | hugolib/site_output.go | 86 |
1 files changed, 47 insertions, 39 deletions
diff --git a/hugolib/site_output.go b/hugolib/site_output.go index 5a99692a3..497092e8c 100644 --- a/hugolib/site_output.go +++ b/hugolib/site_output.go @@ -24,9 +24,46 @@ import ( "github.com/spf13/cast" ) +func createDefaultOutputFormats(allFormats output.Formats, cfg config.Provider) map[string]output.Formats { + rssOut, _ := allFormats.GetByName(output.RSSFormat.Name) + htmlOut, _ := allFormats.GetByName(output.HTMLFormat.Name) + robotsOut, _ := allFormats.GetByName(output.RobotsTxtFormat.Name) + sitemapOut, _ := allFormats.GetByName(output.SitemapFormat.Name) + + // TODO(bep) this mumbo jumbo is deprecated and should be removed, but there are tests that + // depends on this, so that will have to wait. + rssBase := cfg.GetString("rssURI") + if rssBase == "" || rssBase == "index.xml" { + rssBase = rssOut.BaseName + } else { + // Remove in Hugo 0.36. + helpers.Deprecated("Site config", "rssURI", "Set baseName in outputFormats.RSS", true) + // RSS has now a well defined media type, so strip any suffix provided + rssBase = strings.TrimSuffix(rssBase, path.Ext(rssBase)) + } + + rssOut.BaseName = rssBase + + return map[string]output.Formats{ + KindPage: output.Formats{htmlOut}, + KindHome: output.Formats{htmlOut, rssOut}, + KindSection: output.Formats{htmlOut, rssOut}, + KindTaxonomy: output.Formats{htmlOut, rssOut}, + KindTaxonomyTerm: output.Formats{htmlOut, rssOut}, + // Below are for conistency. They are currently not used during rendering. + kindRSS: output.Formats{rssOut}, + kindSitemap: output.Formats{sitemapOut}, + kindRobotsTXT: output.Formats{robotsOut}, + kind404: output.Formats{htmlOut}, + } + +} + func createSiteOutputFormats(allFormats output.Formats, cfg config.Provider) (map[string]output.Formats, error) { + defaultOutputFormats := createDefaultOutputFormats(allFormats, cfg) + if !cfg.IsSet("outputs") { - return createDefaultOutputFormats(allFormats, cfg) + return defaultOutputFormats, nil } outFormats := make(map[string]output.Formats) @@ -37,6 +74,8 @@ func createSiteOutputFormats(allFormats output.Formats, cfg config.Provider) (ma return outFormats, nil } + seen := make(map[string]bool) + for k, v := range outputs { var formats output.Formats vals := cast.ToStringSlice(v) @@ -48,52 +87,21 @@ func createSiteOutputFormats(allFormats output.Formats, cfg config.Provider) (ma formats = append(formats, f) } + // This effectively prevents empty outputs entries for a given Kind. + // We need at least one. if len(formats) > 0 { + seen[k] = true outFormats[k] = formats } } - // Make sure every kind has at least one output format - for _, kind := range allKinds { - if _, found := outFormats[kind]; !found { - outFormats[kind] = output.Formats{output.HTMLFormat} + // Add defaults for the entries not provided by the user. + for k, v := range defaultOutputFormats { + if !seen[k] { + outFormats[k] = v } } return outFormats, nil } - -func createDefaultOutputFormats(allFormats output.Formats, cfg config.Provider) (map[string]output.Formats, error) { - outFormats := make(map[string]output.Formats) - rssOut, _ := allFormats.GetByName(output.RSSFormat.Name) - htmlOut, _ := allFormats.GetByName(output.HTMLFormat.Name) - - for _, kind := range allKinds { - var formats output.Formats - // All have HTML - formats = append(formats, htmlOut) - - // All but page have RSS - if kind != KindPage { - - rssBase := cfg.GetString("rssURI") - if rssBase == "" || rssBase == "index.xml" { - rssBase = rssOut.BaseName - } else { - // Remove in Hugo 0.36. - helpers.Deprecated("Site config", "rssURI", "Set baseName in outputFormats.RSS", true) - // RSS has now a well defined media type, so strip any suffix provided - rssBase = strings.TrimSuffix(rssBase, path.Ext(rssBase)) - } - - rssOut.BaseName = rssBase - formats = append(formats, rssOut) - - } - - outFormats[kind] = formats - } - - return outFormats, nil -} |