Taxonomies can now be provided as a single string value if there is only one in front...
authorspf13 <steve.francia@gmail.com>
Fri, 5 Sep 2014 13:29:01 +0000 (09:29 -0400)
committerspf13 <steve.francia@gmail.com>
Fri, 5 Sep 2014 13:29:01 +0000 (09:29 -0400)
hugolib/page_taxonomy_test.go
hugolib/site.go
hugolib/site_test.go

index 68ff4171fddbbb884e72eb6852d0d2b146ef9528..f372a595a4ac9e9fd579b4bccd6bf047d9787d2a 100644 (file)
@@ -20,6 +20,12 @@ categories: 'd'
 ---
 YAML frontmatter with tags and categories taxonomy.`
 
+var PAGE_YAML_WITH_TAXONOMIES_C = `---
+tags: 'e'
+categories: 'd'
+---
+YAML frontmatter with tags and categories taxonomy.`
+
 var PAGE_JSON_WITH_TAXONOMIES = `{
   "categories": "d",
   "tags": [
@@ -41,6 +47,7 @@ func TestParseTaxonomies(t *testing.T) {
                PAGE_JSON_WITH_TAXONOMIES,
                PAGE_YAML_WITH_TAXONOMIES_A,
                PAGE_YAML_WITH_TAXONOMIES_B,
+               PAGE_YAML_WITH_TAXONOMIES_C,
        } {
 
                p, _ := NewPage("page/with/taxonomy")
@@ -50,11 +57,17 @@ func TestParseTaxonomies(t *testing.T) {
                }
 
                param := p.GetParam("tags")
-               params := param.([]string)
 
-               expected := []string{"a", "b", "c"}
-               if !compareStringSlice(params, expected) {
-                       t.Errorf("Expected %s: got: %s", expected, params)
+               if params, ok := param.([]string); ok {
+                       expected := []string{"a", "b", "c"}
+                       if !compareStringSlice(params, expected) {
+                               t.Errorf("Expected %s: got: %s", expected, params)
+                       }
+               } else if params, ok := param.(string); ok {
+                       expected := "e"
+                       if params != expected {
+                               t.Errorf("Expected %s: got: %s", expected, params)
+                       }
                }
 
                param = p.GetParam("categories")
index 104322bfc06b58f459e068eacfcc800943555946..c50cea0a6bc8be69eced0b5a1881086c87f1b37f 100644 (file)
@@ -535,13 +535,14 @@ func (s *Site) assembleTaxonomies() {
                        }
 
                        if vals != nil {
-                               v, ok := vals.([]string)
-                               if ok {
+                               if v, ok := vals.([]string); ok {
                                        for _, idx := range v {
                                                x := WeightedPage{weight.(int), p}
-
                                                s.Taxonomies[plural].Add(idx, x)
                                        }
+                               } else if v, ok := vals.(string); ok {
+                                       x := WeightedPage{weight.(int), p}
+                                       s.Taxonomies[plural].Add(v, x)
                                } else {
                                        jww.ERROR.Printf("Invalid %s in %s\n", plural, p.File.FileName)
                                }
index aef1e04432bbd82e79c6be99f3125dfb6ba869d8..44acb0cc5f7f85d365041a7775b0068ae6e664a1 100644 (file)
@@ -560,7 +560,7 @@ categories_weight = 44
 Front Matter with weighted tags and categories`)
 
 var PAGE_WITH_WEIGHTED_TAXONOMIES_1 = []byte(`+++
-tags = [ "a" ]
+tags = "a"
 tags_weight = 33
 title = "bar"
 categories = [ "d", "e" ]