mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 06:52:11 -05:00
Taxonomies can now be provided as a single string value if there is only one in frontmatter (tag = "val" vs tag = ["val"])
This commit is contained in:
parent
1b7f18e391
commit
4bb5e326db
3 changed files with 22 additions and 8 deletions
|
@ -20,6 +20,12 @@ categories: 'd'
|
||||||
---
|
---
|
||||||
YAML frontmatter with tags and categories taxonomy.`
|
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 = `{
|
var PAGE_JSON_WITH_TAXONOMIES = `{
|
||||||
"categories": "d",
|
"categories": "d",
|
||||||
"tags": [
|
"tags": [
|
||||||
|
@ -41,6 +47,7 @@ func TestParseTaxonomies(t *testing.T) {
|
||||||
PAGE_JSON_WITH_TAXONOMIES,
|
PAGE_JSON_WITH_TAXONOMIES,
|
||||||
PAGE_YAML_WITH_TAXONOMIES_A,
|
PAGE_YAML_WITH_TAXONOMIES_A,
|
||||||
PAGE_YAML_WITH_TAXONOMIES_B,
|
PAGE_YAML_WITH_TAXONOMIES_B,
|
||||||
|
PAGE_YAML_WITH_TAXONOMIES_C,
|
||||||
} {
|
} {
|
||||||
|
|
||||||
p, _ := NewPage("page/with/taxonomy")
|
p, _ := NewPage("page/with/taxonomy")
|
||||||
|
@ -50,12 +57,18 @@ func TestParseTaxonomies(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
param := p.GetParam("tags")
|
param := p.GetParam("tags")
|
||||||
params := param.([]string)
|
|
||||||
|
|
||||||
|
if params, ok := param.([]string); ok {
|
||||||
expected := []string{"a", "b", "c"}
|
expected := []string{"a", "b", "c"}
|
||||||
if !compareStringSlice(params, expected) {
|
if !compareStringSlice(params, expected) {
|
||||||
t.Errorf("Expected %s: got: %s", expected, params)
|
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")
|
param = p.GetParam("categories")
|
||||||
singleparam := param.(string)
|
singleparam := param.(string)
|
||||||
|
|
|
@ -535,13 +535,14 @@ func (s *Site) assembleTaxonomies() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if vals != nil {
|
if vals != nil {
|
||||||
v, ok := vals.([]string)
|
if v, ok := vals.([]string); ok {
|
||||||
if ok {
|
|
||||||
for _, idx := range v {
|
for _, idx := range v {
|
||||||
x := WeightedPage{weight.(int), p}
|
x := WeightedPage{weight.(int), p}
|
||||||
|
|
||||||
s.Taxonomies[plural].Add(idx, x)
|
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 {
|
} else {
|
||||||
jww.ERROR.Printf("Invalid %s in %s\n", plural, p.File.FileName)
|
jww.ERROR.Printf("Invalid %s in %s\n", plural, p.File.FileName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -560,7 +560,7 @@ categories_weight = 44
|
||||||
Front Matter with weighted tags and categories`)
|
Front Matter with weighted tags and categories`)
|
||||||
|
|
||||||
var PAGE_WITH_WEIGHTED_TAXONOMIES_1 = []byte(`+++
|
var PAGE_WITH_WEIGHTED_TAXONOMIES_1 = []byte(`+++
|
||||||
tags = [ "a" ]
|
tags = "a"
|
||||||
tags_weight = 33
|
tags_weight = 33
|
||||||
title = "bar"
|
title = "bar"
|
||||||
categories = [ "d", "e" ]
|
categories = [ "d", "e" ]
|
||||||
|
|
Loading…
Reference in a new issue