mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-20 16:12:20 +00:00
Handle disabled RSS even if it's defined in outputs
See https://github.com/gohugoio/hugo/issues/6897#issuecomment-587947078
This commit is contained in:
parent
c7975b48b6
commit
da54787cfa
4 changed files with 31 additions and 8 deletions
|
@ -266,3 +266,18 @@ headless: true
|
||||||
b.Assert(resource.RelPermalink(), qt.Equals, "/blog/sect/no-publishresources/data.json")
|
b.Assert(resource.RelPermalink(), qt.Equals, "/blog/sect/no-publishresources/data.json")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/gohugoio/hugo/issues/6897#issuecomment-587947078
|
||||||
|
func TestDisableRSSWithRSSInCustomOutputs(t *testing.T) {
|
||||||
|
b := newTestSitesBuilder(t).WithConfigFile("toml", `
|
||||||
|
disableKinds = ["taxonomy", "taxonomyTerm", "RSS"]
|
||||||
|
[outputs]
|
||||||
|
home = [ "HTML", "RSS" ]
|
||||||
|
`).Build(BuildCfg{})
|
||||||
|
|
||||||
|
// The config above is a little conflicting, but it exists in the real world.
|
||||||
|
// In Hugo 0.65 we consolidated the code paths and made RSS a pure output format,
|
||||||
|
// but we should make sure to not break existing sites.
|
||||||
|
b.Assert(b.CheckExists("public/index.xml"), qt.Equals, false)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -432,7 +432,8 @@ func newSite(cfg deps.DepsCfg) (*Site, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if disabledKinds[kindRSS] {
|
rssDisabled := disabledKinds[kindRSS]
|
||||||
|
if rssDisabled {
|
||||||
// Legacy
|
// Legacy
|
||||||
tmp := siteOutputFormatsConfig[:0]
|
tmp := siteOutputFormatsConfig[:0]
|
||||||
for _, x := range siteOutputFormatsConfig {
|
for _, x := range siteOutputFormatsConfig {
|
||||||
|
@ -443,7 +444,7 @@ func newSite(cfg deps.DepsCfg) (*Site, error) {
|
||||||
siteOutputFormatsConfig = tmp
|
siteOutputFormatsConfig = tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
outputFormats, err := createSiteOutputFormats(siteOutputFormatsConfig, cfg.Language)
|
outputFormats, err := createSiteOutputFormats(siteOutputFormatsConfig, cfg.Language, rssDisabled)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ package hugolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/config"
|
"github.com/gohugoio/hugo/config"
|
||||||
"github.com/gohugoio/hugo/output"
|
"github.com/gohugoio/hugo/output"
|
||||||
|
@ -54,7 +55,7 @@ func createDefaultOutputFormats(allFormats output.Formats, cfg config.Provider)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSiteOutputFormats(allFormats output.Formats, cfg config.Provider) (map[string]output.Formats, error) {
|
func createSiteOutputFormats(allFormats output.Formats, cfg config.Provider, rssDisabled bool) (map[string]output.Formats, error) {
|
||||||
defaultOutputFormats := createDefaultOutputFormats(allFormats, cfg)
|
defaultOutputFormats := createDefaultOutputFormats(allFormats, cfg)
|
||||||
|
|
||||||
if !cfg.IsSet("outputs") {
|
if !cfg.IsSet("outputs") {
|
||||||
|
@ -82,6 +83,12 @@ func createSiteOutputFormats(allFormats output.Formats, cfg config.Provider) (ma
|
||||||
for _, format := range vals {
|
for _, format := range vals {
|
||||||
f, found := allFormats.GetByName(format)
|
f, found := allFormats.GetByName(format)
|
||||||
if !found {
|
if !found {
|
||||||
|
if rssDisabled && strings.EqualFold(format, "RSS") {
|
||||||
|
// This is legacy behaviour. We used to have both
|
||||||
|
// a RSS page kind and output format.
|
||||||
|
continue
|
||||||
|
|
||||||
|
}
|
||||||
return nil, fmt.Errorf("failed to resolve output format %q from site config", format)
|
return nil, fmt.Errorf("failed to resolve output format %q from site config", format)
|
||||||
}
|
}
|
||||||
formats = append(formats, f)
|
formats = append(formats, f)
|
||||||
|
|
|
@ -341,7 +341,7 @@ func TestCreateSiteOutputFormats(t *testing.T) {
|
||||||
cfg := viper.New()
|
cfg := viper.New()
|
||||||
cfg.Set("outputs", outputsConfig)
|
cfg.Set("outputs", outputsConfig)
|
||||||
|
|
||||||
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg)
|
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg, false)
|
||||||
c.Assert(err, qt.IsNil)
|
c.Assert(err, qt.IsNil)
|
||||||
c.Assert(outputs[page.KindSection], deepEqualsOutputFormats, output.Formats{output.JSONFormat})
|
c.Assert(outputs[page.KindSection], deepEqualsOutputFormats, output.Formats{output.JSONFormat})
|
||||||
c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.JSONFormat})
|
c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.JSONFormat})
|
||||||
|
@ -371,7 +371,7 @@ func TestCreateSiteOutputFormats(t *testing.T) {
|
||||||
}
|
}
|
||||||
cfg.Set("outputs", outputsConfig)
|
cfg.Set("outputs", outputsConfig)
|
||||||
|
|
||||||
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg)
|
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg, false)
|
||||||
c.Assert(err, qt.IsNil)
|
c.Assert(err, qt.IsNil)
|
||||||
c.Assert(outputs[page.KindTaxonomyTerm], deepEqualsOutputFormats, output.Formats{output.JSONFormat})
|
c.Assert(outputs[page.KindTaxonomyTerm], deepEqualsOutputFormats, output.Formats{output.JSONFormat})
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ func TestCreateSiteOutputFormatsInvalidConfig(t *testing.T) {
|
||||||
cfg := viper.New()
|
cfg := viper.New()
|
||||||
cfg.Set("outputs", outputsConfig)
|
cfg.Set("outputs", outputsConfig)
|
||||||
|
|
||||||
_, err := createSiteOutputFormats(output.DefaultFormats, cfg)
|
_, err := createSiteOutputFormats(output.DefaultFormats, cfg, false)
|
||||||
c.Assert(err, qt.Not(qt.IsNil))
|
c.Assert(err, qt.Not(qt.IsNil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,7 +403,7 @@ func TestCreateSiteOutputFormatsEmptyConfig(t *testing.T) {
|
||||||
cfg := viper.New()
|
cfg := viper.New()
|
||||||
cfg.Set("outputs", outputsConfig)
|
cfg.Set("outputs", outputsConfig)
|
||||||
|
|
||||||
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg)
|
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg, false)
|
||||||
c.Assert(err, qt.IsNil)
|
c.Assert(err, qt.IsNil)
|
||||||
c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat})
|
c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat})
|
||||||
}
|
}
|
||||||
|
@ -423,7 +423,7 @@ func TestCreateSiteOutputFormatsCustomFormats(t *testing.T) {
|
||||||
customHTML = output.Format{Name: "HTML", BaseName: "customHTML"}
|
customHTML = output.Format{Name: "HTML", BaseName: "customHTML"}
|
||||||
)
|
)
|
||||||
|
|
||||||
outputs, err := createSiteOutputFormats(output.Formats{customRSS, customHTML}, cfg)
|
outputs, err := createSiteOutputFormats(output.Formats{customRSS, customHTML}, cfg, false)
|
||||||
c.Assert(err, qt.IsNil)
|
c.Assert(err, qt.IsNil)
|
||||||
c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{customHTML, customRSS})
|
c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{customHTML, customRSS})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue