page.KindSection: {htmlOut, rssOut},
page.KindTaxonomy: {htmlOut, rssOut},
page.KindTaxonomyTerm: {htmlOut, rssOut},
- // Below are for conistency. They are currently not used during rendering.
+ // Below are for consistency. They are currently not used during rendering.
kindRSS: {rssOut},
kindSitemap: {sitemapOut},
kindRobotsTXT: {robotsOut},
seen := make(map[string]bool)
for k, v := range outputs {
+ k = getKind(k)
+ if k == "" {
+ // Invalid kind
+ continue
+ }
var formats output.Formats
vals := cast.ToStringSlice(v)
for _, format := range vals {
}
func TestCreateSiteOutputFormats(t *testing.T) {
- assert := require.New(t)
- outputsConfig := map[string]interface{}{
- page.KindHome: []string{"HTML", "JSON"},
- page.KindSection: []string{"JSON"},
- }
+ t.Run("Basic", func(t *testing.T) {
+ assert := require.New(t)
- cfg := viper.New()
- cfg.Set("outputs", outputsConfig)
+ outputsConfig := map[string]interface{}{
+ page.KindHome: []string{"HTML", "JSON"},
+ page.KindSection: []string{"JSON"},
+ }
- outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg)
- assert.NoError(err)
- assert.Equal(output.Formats{output.JSONFormat}, outputs[page.KindSection])
- assert.Equal(output.Formats{output.HTMLFormat, output.JSONFormat}, outputs[page.KindHome])
-
- // Defaults
- assert.Equal(output.Formats{output.HTMLFormat, output.RSSFormat}, outputs[page.KindTaxonomy])
- assert.Equal(output.Formats{output.HTMLFormat, output.RSSFormat}, outputs[page.KindTaxonomyTerm])
- assert.Equal(output.Formats{output.HTMLFormat}, outputs[page.KindPage])
-
- // These aren't (currently) in use when rendering in Hugo,
- // but the pages needs to be assigned an output format,
- // so these should also be correct/sensible.
- assert.Equal(output.Formats{output.RSSFormat}, outputs[kindRSS])
- assert.Equal(output.Formats{output.SitemapFormat}, outputs[kindSitemap])
- assert.Equal(output.Formats{output.RobotsTxtFormat}, outputs[kindRobotsTXT])
- assert.Equal(output.Formats{output.HTMLFormat}, outputs[kind404])
+ cfg := viper.New()
+ cfg.Set("outputs", outputsConfig)
+
+ outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg)
+ assert.NoError(err)
+ assert.Equal(output.Formats{output.JSONFormat}, outputs[page.KindSection])
+ assert.Equal(output.Formats{output.HTMLFormat, output.JSONFormat}, outputs[page.KindHome])
+
+ // Defaults
+ assert.Equal(output.Formats{output.HTMLFormat, output.RSSFormat}, outputs[page.KindTaxonomy])
+ assert.Equal(output.Formats{output.HTMLFormat, output.RSSFormat}, outputs[page.KindTaxonomyTerm])
+ assert.Equal(output.Formats{output.HTMLFormat}, outputs[page.KindPage])
+
+ // These aren't (currently) in use when rendering in Hugo,
+ // but the pages needs to be assigned an output format,
+ // so these should also be correct/sensible.
+ assert.Equal(output.Formats{output.RSSFormat}, outputs[kindRSS])
+ assert.Equal(output.Formats{output.SitemapFormat}, outputs[kindSitemap])
+ assert.Equal(output.Formats{output.RobotsTxtFormat}, outputs[kindRobotsTXT])
+ assert.Equal(output.Formats{output.HTMLFormat}, outputs[kind404])
+
+ })
+
+ // Issue #4528
+ t.Run("Mixed case", func(t *testing.T) {
+ assert := require.New(t)
+ cfg := viper.New()
+
+ outputsConfig := map[string]interface{}{
+ "taxonomyterm": []string{"JSON"},
+ }
+ cfg.Set("outputs", outputsConfig)
+
+ outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg)
+ assert.NoError(err)
+ assert.Equal(output.Formats{output.JSONFormat}, outputs[page.KindTaxonomyTerm])
+
+ })
}
package page
+import "strings"
+
const (
KindPage = "page"
KindTaxonomy = "taxonomy"
KindTaxonomyTerm = "taxonomyTerm"
)
+
+var kindMap = map[string]string{
+ strings.ToLower(KindPage): KindPage,
+ strings.ToLower(KindHome): KindHome,
+ strings.ToLower(KindSection): KindSection,
+ strings.ToLower(KindTaxonomy): KindTaxonomy,
+ strings.ToLower(KindTaxonomyTerm): KindTaxonomyTerm,
+}
+
+// GetKind gets the page kind given a string, empty if not found.
+func GetKind(s string) string {
+ return kindMap[strings.ToLower(s)]
+}