From 4bb5e326dbf0f732dd5db45a47fa25999806111e Mon Sep 17 00:00:00 2001 From: spf13 Date: Fri, 5 Sep 2014 09:29:01 -0400 Subject: [PATCH] Taxonomies can now be provided as a single string value if there is only one in frontmatter (tag = "val" vs tag = ["val"]) --- hugolib/page_taxonomy_test.go | 21 +++++++++++++++++---- hugolib/site.go | 7 ++++--- hugolib/site_test.go | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/hugolib/page_taxonomy_test.go b/hugolib/page_taxonomy_test.go index 68ff4171f..f372a595a 100644 --- a/hugolib/page_taxonomy_test.go +++ b/hugolib/page_taxonomy_test.go @@ -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") diff --git a/hugolib/site.go b/hugolib/site.go index 104322bfc..c50cea0a6 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -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) } diff --git a/hugolib/site_test.go b/hugolib/site_test.go index aef1e0443..44acb0cc5 100644 --- a/hugolib/site_test.go +++ b/hugolib/site_test.go @@ -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" ]